I’m trying to join two tables: Rooms and Room_Types (which have a relationship already). The thing is, I’m trying to do something like:
room = Room.all :conditions => ['rooms.id = ?', @room_id],
:joins => :room_type
room.to_json
..and this JSON is being sent to my view.
However, the JSON is only showing the fields of the Room table and is not including the Room_Type fields, and I need both tables’ fields in this JSON. How can I accomplish this?
:joinsonly performs aJOIN. As in SQL, this does not add the JOINed table’s columns to the results. If you want to do that you should use:includeinstead:Or, in Rails 3 parlance: