I finally came back around to playing with this. A very important thing
to note is that you get the same error message whether you do it
completely wrong or if you just pluralize your models wrong.
In this example
A Customer has many cars; A Car belongs to exactly one customer
A Car has many work orders; A Work Order belongs to one car
A Work Order has many purchases; A purchase belongs to one Work Order
A purchase has exactly one part; A part has many purchases
A Work Order has many comments
receipt = WorkOrder.find(params[:id])
@receipt = receipt.to_json(
:include => {
:car => {
:include => :customer
},
:purchases => {
:include => :part
},
:comments => {}
}
)
I had to troubleshoot for over an hour until I finally got it right. If
I had been careful with the pluralization I would have gotten there a
lot sooner.
# All of these simpler configurations work as well
:include => :purchases
:include => {
:purchases => {
:include => :part
}
}
:include => {
:purchases => {
:include => {
:part => {
:only => :part
}
}
}
}
:include => {
:purchases => {
:include => {
:part => {
:only => :part
}
},
:only => :price
}
}
# array
:include => [
:purchases,
:car
]
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.