You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my model, I have Products and ProductUnits. A product has many ProductUnits associated with it. Since I need some attributes on the relationship, I've created a ProductComponent model which points to a single ProductUnit and associate Products to ProductUnits through the ProductComponent. Here are the associations in the Product class:
This says that calling someprod.units returns a list of ProductUnit instances and prod.product_components returns a list of ProductComponent instances.
So in RABL, I defined a product like so...
object @prod
attributes :id, :active, :name, :description
child :units do
attributes :id, :name
end
When I look at the resultant JSON, there's no .units array hanging off the product. So, what does it look like?
{
id:1, active:true, name:"prodname", description:"this is a product",
product_units:[
{id:9, name:"some unit"}
]
}
Yes, an association :through, using a :source type, ends up rendering to the source's class name instead of what you've defined in the child node in RABL. But I found that using an alias works...but it looks funny:
child :units => :units do
...
end
This workaround....er...works, but it seems unnecessary. I'd think that the association name would be preserved. Am I thinking about this incorrectly?
The text was updated successfully, but these errors were encountered:
In my model, I have Products and ProductUnits. A product has many ProductUnits associated with it. Since I need some attributes on the relationship, I've created a ProductComponent model which points to a single ProductUnit and associate Products to ProductUnits through the ProductComponent. Here are the associations in the Product class:
This says that calling someprod.units returns a list of ProductUnit instances and prod.product_components returns a list of ProductComponent instances.
So in RABL, I defined a product like so...
When I look at the resultant JSON, there's no .units array hanging off the product. So, what does it look like?
Yes, an association :through, using a :source type, ends up rendering to the source's class name instead of what you've defined in the child node in RABL. But I found that using an alias works...but it looks funny:
This workaround....er...works, but it seems unnecessary. I'd think that the association name would be preserved. Am I thinking about this incorrectly?
The text was updated successfully, but these errors were encountered: