views:

45

answers:

0

I've got a Rails app returning data via JSON and XML.

In the controller, I've got something like this:

respond_to do |format|
  format.xml { render :xml => @customers.to_xml(:include => [:invoices])) }
end

The Rails app returns the customers in a pretty XML doc but it always shows the 'invoices' array as empty (i.e. no data for the relationship).

The thing is, I can use the Rails console to walk these relationships and they are indeed filled with content.

The has_many is defined as such in the Customer model:

has_many :invoices, :foreign_key => "bill_to", :primary_key => "cust_account", :include => [:invoice_lines, :blanket_releases], :conditions => ["invoice_lines.remaining_physical > 0 AND sales_type = 'Blanket order'"]

As you can see, the DB is non-Rails standard (legacy).

Are there any tricks or gotchas related to this that might cause the 'aCustomer.invoices' to come back as [] when called via the controller/output via XML but not when using the console (yes, it is the same database in both instances)?

Any other debugging tips anyone can suggest?