Is there a way to "un-nest" association? #290
-
Hi! Let's say I have following models:
Situation: In JBuilder I used to do it this way: json.partial! "bar/bar", document: foo_bar.bar
json.field_a foo_bar.a It would put everything at the same nesting level. Something like: {
// from Bar model via partial
"id": 1,
"name": "Bar",
// from FooBar model
"field_a": "A"
} Is something like that possible in Alba? In best case scenario I'd love to write it like this. Though I can't find anything alike in docs or examples. class FooBarResource
include Alba::Resource
one :bar, resource: BarResource, unnest: true
attributes :a
end |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
There might be a better answer for this, but one possible solution would be to simply define a method in your resource which calls the relevant method on the associated model. |
Beta Was this translation helpful? Give feedback.
There might be a better answer for this, but one possible solution would be to simply define a method in your resource which calls the relevant method on the associated model.