ruby on rails - has_many, belongs_to association where has_many associated model has two alias fk in belongs_to associated_model -
I have a user model that has many fights under the boy user.
There is two foreign keys in the battle table that the user is in reference to PK - Challenger_ID and Challenge_ID.
This is the trick that I write to the Association on the user model so that he can combat the fight where the user_id = challenger_id and challenge_id?
I believe you should use two different organizations and return all the fights Make a method for Is it not possible on some days, you only need to get fights
, where there was some @ user
challenge
class users & lt; ActiveRecord :: Base is - medium: fights_as_challenger ,: foreign_key = & gt; : Challenger_id,: class_name = & gt; "Fight" is_maya: fights_as_challengee ,: foreign_key = & gt; : Challengee_id,: class_name = & gt; "Fight" def all_fights self.fights_as_challenger + self.fights_as_challengee end and
Comments
Post a Comment