ruby - Rails has_one per scope -
i have 3 models follows:
class user < activerecord::base ... has_many :feeds ... end class project < acticerecord::base ... has_many :feeds has_many :users, through: :feeds ... end class feed < activerecord::base ... belongs_to :user belongs_to :project ... end
i want model situation user can have maximum of 1 feed per project. know can check in custom validator within feed class, there way model using activerecord associations?
you can on feed.rb:
validates :user_id, :uniqueness => {:scope => :project_id}
Comments
Post a Comment