ruby on rails 4 - merge ActiveRecord::Relation with ActiveRecord::Associations -
i have 2 models
class user < activerecord::base has_many :games def created_games game.where(created_by: self.id) end end class game < activerecord::base belongs_to :user end u = user.take joined_games = u.games created_games = u.created_games
the variable joined_games instance of activerecord::associations, , created_games instance of activerecord::relation.
is there way can join joined_games , created_games together?
try adding scope in user model
scope :joined_games, where(user_id: self.id, created_by: self.id)
Comments
Post a Comment