I’m having a hard time wrapping my head around model association in ruby on rails.
Let’s say I have a Game model and a GameStatus model. I want each Game to have one GameStatus and a GameStatus can have many Games. How would I go about connecting those two. I have a game_status_id in my Game table migration, and I currently have a belongs_to :game in my GameStatus model. How do I get the Game model to eagerly load its GameStatus? And on the other hand, can I use the GameStatus model to get all the Games with that status, preferably filtered by some other Game property?
I’m using Ruby On Rails 3
If a GameStatus
has_many :games, then a Gamebelongs_to :game_status. You need to define both sides of the relationship.Although, I’m racking my brain trying to figure out a meaning to an architecture as you describe… Are you sure it’s not vice versa? That one Game can have many Statuses, which belong to that Game in turn?