Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class User < ActiveRecord::Base
- has_many :claimant_disputes, class_name: 'Dispute', :foreign_key => :claimant_id
- has_many :indicted_disputes, class_name: 'Dispute', :foreign_key => :indicted_id
- end
- class Dispute < ActiveRecord::Base
- belongs_to :claimant, class_name: 'User', :foreign_key => :claimant_id
- belongs_to :indicted, class_name: 'User', :foreign_key => :indicted_id
- end
- #соответственно юзаеш как обычно
- dispute = Dispute.create(:name=>'Dispute1')
- cl_user = User.create(:name=>'Claimant user')
- in_user = User.create(:name=>'Indicted user')
- #ну и связывание работает в обе стороны
- dispute.claimant = cl_user
- in_user.indicted_disputes << dispute
- #в результате
- dispute.claimant #первый юзер
- dispute.indicted #второй юзер
- in_user.indicted_disputes #для второго юзера все его индиктед диспуты в данном случае один шо мы создали в списке
- in_user.claimant_disputed #для второго юзера все его клаймант диспуты в данном случае пустой список
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement