Hi,
I’ve got a relationship through a one_to_many :though relationship:
Controller:
class TodaysOrdersController < ApplicationController
respond_to :json
before_filter :require_user
authorize_resource :class => false
def create
@patient = Patient.find(params[:patient_id])
@todays_order_of_patient =
DailyOrder.create_or_find_todays_order_for_patient @patient
respond_with(@todays_order_of_patient, :location => nil, :include
=> :courses)
end
end
Model:
class DailyOrder < ActiveRecord::Base
Relationships
has_many :course_orders
has_many :courses, :through => :course_orders
has_many :patient_orders
has_one :patient, :through => :patient_orders
def self.create_or_find_todays_order_for_patient(patient)
if(!patient.todays_order)
daily_order = DailyOrder.create
PatientOrder.create(:patient => patient, :daily_order =>
daily_order, :order_for_date => Date.today)
daily_order
else
patient.todays_order
end
end
end
The rendering result of the controller response with something like
that:
{“marked_for_destruction”=>false, “changed_attributes”=>{},
“attributes”=> {“additional_information”=>"…", “id”=>“594369222”},
“readonly”=>false, “errors”=>{}, “previously_changed”=>{},
“destroyed”=>false, “attributes_cache”=>{}, “new_record”=>false}
But i want the “right"json output which looks like that:
{“additional_information”=>”…", “id”=>“594369222”}
Do you know whats wrong here?