Created
November 19, 2012 08:44
-
-
Save danielevans/4109614 to your computer and use it in GitHub Desktop.
Rails form of Brian's example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| irb(main):007:0> g = Game.joins("INNER JOIN (SELECT * FROM scores WHERE player = 'brian') s1 on s1.game_id = games.id").joins("INNER JOIN (SELECT * FROM scores WHERE player = 'dj') s2 on s2.game_id = games.id").includes(:scores) | |
| Game Load (0.3ms) SELECT "games".* FROM "games" INNER JOIN (SELECT * FROM scores WHERE player = 'brian') s1 on s1.game_id = games.id INNER JOIN (SELECT * FROM scores WHERE player = 'dj') s2 on s2.game_id = games.id | |
| Score Load (0.3ms) SELECT "scores".* FROM "scores" WHERE "scores"."game_id" IN (1, 3) | |
| => [#<Game id: 1, created_at: "2012-11-19 08:35:03", updated_at: "2012-11-19 08:35:03">, #<Game id: 3, created_at: "2012-11-19 08:36:54", updated_at: "2012-11-19 08:36:54">] | |
| irb(main):008:0> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment