exvayn
exvayn

Reputation: 278

JSON response with nested calculated key in ROR

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

Upvotes: 0

Views: 104

Answers (0)

Related Questions