1
我在這裏有一個多對多的關係。Rails - 多對多關聯(將用戶添加到組)SQLite
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
必須有中,我應該推項目,某些用戶項目的方式,對不對?請幫助我,夥計們。
在此先感謝。