I’m sure I’m doing something stupid, but my AR code
@comments = Comment.find(:all, :limit => 10,
:joins => "LEFT JOIN `users` ON comments.user_id = users.id",
:select => 'comments.*, users.theme')
Is returning the correct sql:
SELECT comments.*, users.theme from comments LEFT JOIN users on comments.user_id = users.id
and when I put it into a mysql, I get the results I want, but when I try to access @comment.theme (in an each loop on @comments) after the above AR call is made, theme is not there.
So, is there something special I have to do to the Comments model to allow joins to populate the associated columns? I thought that Rails would just add them as properties I could dot-grab.
Try this:
All the fields are in the array @comments, as Object type Comment, and the field names are as used in the select, with no regard to their original source.
Good luck.