Suggestion
A way to filter the parent model using a related model property, something like modify the query before execute him or other solution.
const status = "inStoke";
{
include: [{relation:"productStatus"}],
beforeExecute: query => {
query.where.and.add("product_status.status", "inStoke");
return quey;
}
}
Use Cases
Is useful when you can request just the parent model but still need to filter the results usign a property of other model(table)
Examples
Ex:
i have product
{id: 1, "name": "product 1", "product_group_id": 1},
{id: 2, "name": "product 2", "product_group_id": 2},
{id: 3, "name": "product 3", "product_group_id": 2}
And product_status:
{id: 1, "status": "inStoke", "product_id": 1},
{id: 2, "status": "empty", "product_id": 2},
{id: 3, "status": "unknow", "product_id": 3}
And product_group
{id: 1, "desc": "group 1"},
{id: 2, "desc": "group 2"},
{id: 3, "desc": "group 3"}
I Wanna get all product that belongsTo to the product_group_id = 1 and also have a product_status with status = inStoke.
In SQL would be something like:
SELECT * FROM product \
INNER JOIN product_status ON product.product_id = product_status.product_id \
INNER JOIN product_group ON product.product_group_id = product_group.id \
WHERE product_group.id = 1 AND product_status.status = inStoke;
Acceptance criteria
TBD - will be filled by the team.
Suggestion
A way to filter the parent model using a related model property, something like modify the query before execute him or other solution.
Use Cases
Is useful when you can request just the parent model but still need to filter the results usign a property of other model(table)
Examples
Ex:
i have product
And product_status:
And product_group
I Wanna get all product that belongsTo to the product_group_id = 1 and also have a product_status with status = inStoke.
In SQL would be something like:
Acceptance criteria
TBD - will be filled by the team.