Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

投票模型改变 #21

Closed
destinyd opened this issue Mar 30, 2015 · 2 comments
Closed

投票模型改变 #21

destinyd opened this issue Mar 30, 2015 · 2 comments
Milestone

Comments

@destinyd
Copy link

原来为三层:Vote 一对多 Question 一对多 Answer
新修改之后两层: Vote 一对多 VoteItem
VoteItem一对多 点赞者
VoteItem 还记录提交者(用户)


Vote:

字段

title: 投票主题
finish_at: 生成报告日期
images: 图片
url: 引用网址
token: *短链接,原来已有

关系

user: 创建者
vote_items: 选项
voted_users: 参与者

函数

Vote.rand_next user 针对用户随机提供一个未投票的投票


VoteItem

字段

title: 选项
vote: 投票
praised_users: 点赞者
praised_count: 点赞数

关系

belongs_to :vote, inverse_of: :vote_items 从属投票
belongs_to :user, inverse_of: :vote_items 选项创建者

函数

vote_item.praised_by? user 是否已点赞
vote_item.praise_by user 点赞


User

关系

has_many :votes 创建的投票
has_and_belongs_to_many :voted_votes, class_name: 'Vote', inverse_of: :voted_users 参加的投票
has_many :vote_items 创建的选项
has_and_belongs_to_many :praised_vote_items, class_name: 'VoteItem', inverse_of: :praised_users 赞过的选项

@destinyd destinyd added this to the pinidea 0.2 milestone Mar 30, 2015
@ben7th ben7th modified the milestone: pinidea 0.2 Mar 30, 2015
@fushang318
Copy link

url 字段用不到了,我关联了一个 infocard 模型

@ben7th
Copy link

ben7th commented Jun 23, 2015

已集成到 0.2

@ben7th ben7th closed this as completed Jun 23, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants