loopback icon indicating copy to clipboard operation
loopback copied to clipboard

Filter by properties of related models (use SQL JOIN in queries)

Open bluestaralone opened this issue 12 years ago • 53 comments

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"}}

bluestaralone avatar Oct 23 '14 02:10 bluestaralone

I also have same issue. I have a very bad experience with loopback. This is a major issue should be fixed asap. :(

mdali602 avatar Jan 04 '18 14:01 mdali602

@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 avatar May 16 '18 14:05 kurtommy

@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 avatar May 16 '18 15:05 bajtos

@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?

kurtommy avatar May 16 '18 15:05 kurtommy

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.

barocsi avatar Jun 18 '18 13:06 barocsi

+1

Andresagustin avatar Jun 25 '18 23:06 Andresagustin

Is this going to be implemented on lb4 ? seems unreal at this level to be stuck with things as basic as that.

cantoute avatar Jun 30 '18 22:06 cantoute

@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

kurtommy avatar Jul 01 '18 06:07 kurtommy

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 avatar Jul 02 '18 14:07 bajtos

@bajtos Sorry to bother you, but since the Loopback 4.0 is released is there anything planed for this feature?

Thanks!

dionisisZyg avatar Oct 31 '18 16:10 dionisisZyg

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.

bkstorm avatar Nov 01 '18 09:11 bkstorm

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.

cantoute avatar Nov 01 '18 18:11 cantoute

This is not resolved yet? Thanks

pookdeveloper avatar Dec 02 '18 18:12 pookdeveloper

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

image

Thanks

pookdeveloper avatar Dec 03 '18 15:12 pookdeveloper

@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.

bajtos avatar Dec 03 '18 15:12 bajtos

Is Loopback 4 supporting this now?

afilp avatar Apr 14 '19 09:04 afilp

Is there any update on this?

vncdias avatar May 03 '19 00:05 vncdias

This is completely insane.

Rayjax avatar May 10 '19 10:05 Rayjax

I can do that with typeorm https://typeorm.io/#/

pookdeveloper avatar May 10 '19 10:05 pookdeveloper

@pookdeveloper You mean that you use typeorm as a total replacement of loopback? Or combined?

afilp avatar May 10 '19 11:05 afilp