I have the following code
@asset = Asset.first(
:include => [
:asset_statuses => [
:asset_status_name,
{:asset_location => [
{:asset_floor => :asset_building}
]}
],
:asset_type => [
:asset_category => :asset_department
]
],
(probably not the best DB table desing but that's what I have to use)
The Asset.first
works correctly and it brings back the data correctly but when I try to use the same :include
in the to_json
method it fails with the followings error:
@asset.to_json(
:include => [
:asset_statuses => [
:asset_status_name,
{:asset_location => [
{:asset_floor => :asset_building}
]}
],
:asset_type => [
:asset_category => :asset_department]
]
)
NoMethodError (undefined method `macro' for nil:NilClass):
The to_json
method has the same :include
syntax as find; I don't understand why it is not working.
In case anyone else runs into a bizarre related issue that I did...to_json
will also return this error when you try to include an association that is not defined on the model.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With