ruby on rails - Has_and_belongs_to_many with additional condition -
i have entities: processes , users. have many-to-many relations. user can assigned process different role: admin , owner (or both), , use boolean columns in link table.
here structure:
processes id name users id email processes_users id process_id: fk user_id: fk admin: boolean owner: boolean
is there way make 2 different has_and_belongs_to_many association these models using condition in boolean flags? want use this:
process = process.find(1) process.owners.size process.admins.size # maybe joins process.joins(:owners).includes(:owners)
is there way this?
use has_many :through association http://guides.rubyonrails.org/association_basics.html#choosing-between-has-many-through-and-has-and-belongs-to-many
Comments
Post a Comment