2
class Todo < ActiveRecord::Base
belongs_to :user
belongs_to :assignee, :class_name => "User"
has_many :comments, :dependent => :destroy
has_many :subscribers, :class_name => "User"
end
class User < ActiveRecord::Base
has_many :todos
has_many :assigned_todos, :class_name => 'Todo', :foreign_key => :assignee_id, :dependent => :destroy
has_many :comments, :through => :todos
has_many :subscriptions, :through => :todos, :inverse_of => :subscribers
end
我想让用户订阅todos。简单的导轨模型 - 订阅用户线程
我希望我可以做@ todo.subscribers,并得到用户的列表回来。
问题:
- 是我的阶级关系是否正确?
- 什么数据库结构,我需要为用户,如果有的话?
- 如果有更好的方法,请让我知道。
你试图通过运行这个控制台,看看它是否按照你想要的方式行事? –
是的,我还没有为订户添加表,因为我不确定该模式应该是什么。 – cjm2671
他们订阅了什么?待办事项?你应该把它看作是模型叫做TodosUsers。 –