I’ve got a relationship through a one_to_many :though relationship:
has_one :todays_order, :through => :patient_orders, :source => :daily_order ,:conditions => ["order_for_date = ?", Date.today]
But when I want to render that in a controller like that:
respond_with(@daily_order = Patient.find(params[:patient_id]).todays_order)
I’ll get the following response:
{“marked_for_destruction”=>false,
“changed_attributes”=>{},
“attributes”=>
{“additional_information”=>”….”, “id”=>”594369222”},
“readonly”=>false,
“errors”=>{},
“previously_changed”=>{},
“destroyed”=>false,
“attributes_cache”=>{},
“new_record”=>false}
But output should be something like that:
{“additional_information”=>”….”, “id”=>”594369222”}
Whats wrong here?
P.S.: You can find the complete Controller and Model: http://pastebin.com/VSbvesTn
solved the problem by not rendering the patient.todays_order “relationship”, instead i’m rendering result of an AR query.
So I think you cant render a relationship object directly in rails.