Reputation: 5896
I am attempting to nest some as_json includes. However, only the first shows up. My code is below. In the below case, only the product is rendered. However, if I switch the order of order_pad and product, only the order_pad renders.
#Renders json
def as_json(options={})
super(
:except => [:created_at, :updated_at, :order_pad_id, :product_id],
:include => [
:product => {
:except => [:created_at, :updated_at]
},
:order_pad => {
:except => [:created_at, :updated_at, :user_id],
:include => [
:user => {
:only => [:id, :name_first, :name_last, :company]
}
]
}
]
)
end
Upvotes: 0
Views: 31
Reputation: 44675
You need to send those as two separate hashes:
:include => [
{
:product => {
:except => [:created_at, :updated_at]
}
},
{
:order_pad => {
:except => [:created_at, :updated_at, :user_id],
:include => [
:user => {
:only => [:id, :name_first, :name_last, :company]
}
]
}
}
]
Upvotes: 1