WedTM
WedTM

Reputation: 2647

Rails Has One relation

I have a simple database that has the following relation.

Each Server has one Game.

now the table Game is just a list of the different games that are possible to have on the server.

However, when I do a @server.game, I get a SQL exception because it's trying to find the server's INSTANCE of it's game (Select * from games where games.server_id = 1) I'd really like it just to do (select * from games where games.id = @server.game_id)

Any clues as to how to perform this association?

Upvotes: 1

Views: 297

Answers (1)

DanSingerman
DanSingerman

Reputation: 36532

If Server has a belongs_to association to Game, the underlying SQL will then be what your are looking for

Upvotes: 3

Related Questions