Rails activerecord includes. How to access the included columns?
- by Lee Quarella
I my User has_many :event_patrons and EventPatron belongs_to :user. I would like to slap together the user with one specific event patron with something like this sql statement:
SELECT * FROM `users` INNER JOIN `event_patrons` ON `event_patrons`.`user_id` = `users`.`id` WHERE `event_patrons`.`event_id` = 1
So in rails I tried this:
User.all(:joins => :event_patrons, :condidions => {:event_patrons => {:event_id => 1}})
But that gives me SELECT users.* instead of SELECT *:
SELECT `users`* FROM `users` INNER JOIN `event_patrons` ON `event_patrons`.`user_id` = `users`.`id` WHERE `event_patrons`.`event_id` = 1
I then tried to switch the :joins with :include and got a whole jumbled mess that still returned me only the columns in User and none from EventPatron.
What am I missing?