0

I have a model and I need to group some of relations and make json response.

For example i have Models:

users: {
  orders
  ...
}

orders: {
  order_group
  items
  ...
}

items: { ... }

order_groups: { ... }

I need to return JSON of users with all uniq order_groups and all items in each order_group:

users: [
  {
    order_groups: [
      {
        items: [ ... ]
      }
    ]
  }
}

I have jBuilder and ALBA serializer.

I'm thinking of choosing ALBA serializer but how to describe this structure of fields? order_groups is calculated key with another calculated key items inside.

I cant make has_many association with calculated column. And I can't create serializer for order_groups model because it doesn't have relation with items

With jbuilder it will be much easier, but lot of people doesn't like it. Trying to go with trends

exvayn
  • 278
  • 1
  • 5
  • Are you asking for a query? Do you have a query? Your question is unclear. – Beartech Dec 08 '22 at 19:16
  • Also please add more than just some JSON examples. You need to add your models code with current relations. – Beartech Dec 08 '22 at 19:17
  • I did show my models with relations. And my questions pretty clear on my opinion. How to serialize calculated nested field – exvayn Dec 09 '22 at 09:02

0 Answers0