Custom Association Method - Can This Be Done

前端 未结 2 519
执笔经年
执笔经年 2021-01-06 04:15

I have three models: Wager, Race, RaceCard and WagerType. I\'ve created a has_many association in Wagers and have added a custom association method (in_wager). The purpose

2条回答
  •  佛祖请我去吃肉
    2021-01-06 04:58

    Do you absolutely need to use an has_many relation ? maybe you could just create a method in the Wager class

    def races
      b = self.race_nbr
      a = b + self.race_card.legs
      Races.find_by_race_card_id(self.id).where('race_nbr BETWEEN ? AND ?', a, b)
    end 
    

    I don't really understand your model, so the request is certainly wrong, but you get the idea...

提交回复
热议问题