-
Notifications
You must be signed in to change notification settings - Fork 28
Description
I would like to add computed properties to a resource, which don't map directly to the database structure. My use case is that I want to perform a count in SQL so I don't have to fetch all resources in the client application (using Ember) just to perform a count.
Model 1 - company
{
"id": "foo",
"name": "",
"stores": ["bar"]
}
Model 2 - store
{
"id": "bar",
"name": "The First Store",
"products": ["baz"]
}
Model 3 - product
{
"id": "baz",
"name": "A Computer"
}
Now I would like to display the amount of products for a single company. I have a database with ~1.000 companies, ~5.000 stores and ~10.000 products. So instead of fetching all stores and products of a company in order to show the amount, I want to query the database directly when fetching a model (because a single SQL-query is much more performant in this case).
If I add the 'amountOfProducts' property to the record in the 'ouput' hook of the company model, it is added under the meta
object.
So my question is, how can I add computed properties to a request response; which do not directly map to the database?
Many thanks in advance!