Filter by properties of related models (use SQL JOIN in queries)
Ex: I have models Book and Category and i want to query Book with condition like below: Books with title contain "Art" and belongs to Category "Programming", please tell me how to do it ? I run this filter in Books model. GET /Books
{"include":{"categories"}, "where": {"title":{"like":"^Art"}, "categories.name":"Programming"}}
I also have same issue. I have a very bad experience with loopback. This is a major issue should be fixed asap. :(
@bajtos I'm looking at other relalted issues but there is not a solution for Mysql, this is very fundamental behaviour, we can filter the results in the UI (left join) we need a proper inner join.
Is there a valid workaround for this?
@kurtommy I am afraid the only workaround is to manually build a native SQL query and execute it from a custom model method, see
- https://loopback.io/doc/en/lb3/Executing-native-SQL.html
- https://loopback.io/doc/en/lb3/Remote-methods.html
@bajtos i'm wondering how the community can use this framework without the basic join i have a generic library and several related entities like songs streams playlist i need to implement a UI filter where the user can type the name of the song so i need an inner join between the library and the song ex:
const filters = {
where: { type: 'Song' },
include: {
relation: 'song',
scope: {
where: { name: 'Mutt' }
}
}
};
but this works as left join. I can filter the library items without a song attached but this break the pagination and is very bad for the unwanted payload and performance
you are pointing to this one: strongloop/loopback-datasource-juggler#730 how to use that?
Boy, its broken at the core just as many "open source" framework, which itself is an illusion. These guys are obviously building apps for clients and not for community. We are good to be testers, pull requesters, fixers, but left fairly behind if it comes to an issue that is not in the interest of loopback main clients.
+1
Is this going to be implemented on lb4 ? seems unreal at this level to be stuck with things as basic as that.
@barocsi well a lot of time the trigger to build huge open source libs is: some company needs and build a framework and then is released publicly eg Angular React .... I believe that the lack of doing SQL Join is a major / huge problems that also the ibm customers will face.
So as @cantoute is saying this situation is absolutely unreal.
I'd like to mention @bajtos as maintainer to ask him if there are some updates on this topic
I don't have any update to share. Our focus is on delivering LoopBack 4.0 GA, we don't have bandwidth to work on this feature until 4.0 is released.
@bajtos Sorry to bother you, but since the Loopback 4.0 is released is there anything planed for this feature?
Thanks!
I can't believe that Loopback doesn't support this basic feature. Does Loopback 4.0 support it? To resolve this problem, I have to use native sql.
Hi,
Seams that the best way is to cast you vote here https://github.com/strongloop/loopback-next/issues/512
Left and Inner Joins on queries. Perhaps just use GraphQL with something like Join Monster https://github.com/stems/join-monster to generate smart SQL behind the scenes.
this feature doesn't seem to be demanded... while to me it seams like an essential and basic need for database driven apps...
Le 1 nov. 2018 à 06:14, Nguyen Hoang [email protected] a écrit :
I can't believe that Loopback doesn't support this basic feature. Does Loopback 4.0 support it? To resolve this problem, I have to use native sql.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/strongloop/loopback/issues/683#issuecomment-434979680, or mute the thread https://github.com/notifications/unsubscribe-auth/AD42peEIKFFTLhlIivQdRbUAbxJt3jpoks5uqrtcgaJpZM4Cx_lQ.
This is not resolved yet? Thanks
if this is not resolved:
https://github.com/strongloop/loopback/issues/683
Why in the docu are this ?
https://loopback.io/doc/en/lb3/Include-filter.html

Thanks
@pookdeveloper IIUC, the condition specified in include.scope.where is applied only to related models being fetched. This issue is asking for a different feature: filter the source models based on properties of the related model.
What does not work:
Books with title contain "Art" and belongs to Category "Programming"
What may work using include.scope.where:
Books with title containing "Art", include data of all related categories with the name "Programming".
I hope my example is making the difference clear.
Is Loopback 4 supporting this now?
Is there any update on this?
This is completely insane.
I can do that with typeorm https://typeorm.io/#/
@pookdeveloper You mean that you use typeorm as a total replacement of loopback? Or combined?