Loopback-datasource-juggler: Search by id of the model related via hasAndBelongsToMany

Created on 25 Mar 2014  路  7Comments  路  Source: loopbackio/loopback-datasource-juggler

Consider the use-case described in #85: a product hasAndBelongsToMany categories.

One can get all products of a category CAT-ID without category data by calling

GET /api/categories/CAT-ID/products

To keep the API consistent with what is available for "product belongsTo category" relationship, LoopBack should support also a request similar to this one:

GET /api/products?filter[where][categoryId]=CAT-ID

The where expression should probably allow multiple ids, something along the lines "where categoryIds include {id-list}".

feature stale

Most helpful comment

+1, any update on this issue? I have a product hasAndBelongsToMany tags relation, but how to do: find all products with a specific tag?

All 7 comments

Can you use the {where: {categoryId: {inq: [id1, id2]}}?

Can you use the {where: {categoryId: {inq: [id1, id2]}}?

I did not try now, but since Product does not have categoryId field (the relation is maintained in a through table), the query will not work. Correct me if I am wrong.

+1 on this feature...

I have a hasMany through relationship for Task and Products, every task can have many products assigned and every product can be on any task.

So, what I want to achieve is to find a task depending on the products assigned, in a mongo like query would be something like

Task.find({
    where: {
        // consider id is part of the through table
        'product.id': id 
    }
});

that would be really helpful for querying related models, another use case could be searching not in the through table but in the related model..

example:

Task.find({
    where: {
        // consider property name to be attribute of Product collection
        'product.name':  'a name' 
    }
});

That would get any task, that has x or y product related if and only if product name matches the term,

That last one would be more than awesome, but not sure about performance and other kind of stuff not visible in my scope.

Please advice.

Cheers,
john

+1, any update on this issue? I have a product hasAndBelongsToMany tags relation, but how to do: find all products with a specific tag?

+1
updates on this issue?

+1

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.

Was this page helpful?
0 / 5 - 0 ratings