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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -