我在这里有一种多对多的关系。
class Project < ActiveRecord::Base
has_many :memberships
has_many :users, :through => :memberships
end
class Membership < ActiveRecord::Base
belongs_to :project
belongs_to :user
end
class User < ActiveRecord::Base
has_many :memberships
has_many :projects, :through => :memberships
end
这是我拥有的三种型号。我想知道如何将这些用户添加到项目中。我必须通过POST获取user_id并将其拆分为“,”来创建另一个数组吗?这个数组可以作为将来的参考,以便在编辑项目时向项目中的所有用户发送通知。
运行时如何获取特定用户的项目
user.projects
必须有一种方法,我应该将项目推送到某个用户的项目,对吗?请帮帮我,伙计们。
提前感谢。