Created
November 20, 2012 19:14
-
-
Save halloffame/4120338 to your computer and use it in GitHub Desktop.
Problem doing a joins in signups
This file contains 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
# Problem: doing a .joins(:user) when using mySQL returns an empty array even when signups exist. The reason I am doing a joins is so that I can sort by user name. | |
### works in SQLlite ### | |
>>> o.signups.joins(:user).order('users.first_name ASC') | |
Signup Load (1.3ms) SELECT "signups".* FROM "signups" INNER JOIN "users" ON "users"."id" = "signups"."user_id" WHERE "signups"."occurrence_id" = 8 ORDER BY users.first_name ASC | |
=> [#<Signups ...>] | |
>>> o.signups | |
Signup Load (1.9ms) SELECT "signups".* FROM "signups" WHERE "signups"."occurrence_id" = 8 | |
=> [#<Signups ...>] | |
### Doesn't work in mySQL ### | |
>>> o.signups.joins(:user).order('users.first_name ASC') | |
Signup Load (1.7ms) SELECT `signups`.* FROM `signups` INNER JOIN `users` ON `users`.`id` = `signups`.`user_id` WHERE `signups`.`occurrence_id` = 8 ORDER BY users.first_name ASC | |
=> [] ### returning empty array, even when i do just .joins(:user) and leave out the order part | |
>>> o.signups | |
Signup Load (0.7ms) SELECT `signups`.* FROM `signups` WHERE `signups`.`occurrence_id` = 8 | |
=> [#<Signups ...>] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment