strongloop / loopback

LoopBack makes it easy to build modern applications that require complex integrations.
http://loopback.io
Other
13.22k stars 1.2k forks source link

Filter on level 2 properties #517

Closed daankets closed 7 years ago

daankets commented 10 years ago

I am trying to use the ?filter rest method, in order to query on nested properties. However, this doesn't seem to work:

/someResource?filter[where][field.subField][like]=abc

neither does this (which I think is wrong anyway):

/someResource?filter[where][field][subField][like]=abc

Any hints?

fabien commented 10 years ago

Which connector are you using?

daankets commented 10 years ago

Memory in dev, mongo in test and beyond. It's the memory connector that has the issues. We use this one for our dev setup as it resets upon restart...

It's the 'dot' notation that is working with mongo.

fabien commented 10 years ago

This is currently a limitation of the memory connector.

@raymondfeng perhaps we can use something like https://github.com/logicalparadox/filtr or https://github.com/crcn/sift.js to enable this

daankets commented 10 years ago

Well, the nice thing about the memory connector is that it resets, so you test every run with a clean sheet. And of course it's rather speedy ;-)

fabien commented 10 years ago

Of course - however, you can easily reset the test database before you start, like this:

app.datasources['db'].automigrate(next);
daankets commented 10 years ago

Will this drop the entire schema?

fabien commented 10 years ago

Yes, but in the case of MongoDB collections will be empties and indexes re-created. There's no real schema, like with SQL databases.

daankets commented 10 years ago

Sure. Just calling it a 'schema' as a 'habit'

fabien commented 10 years ago

Of course! While collections are being recreated, they are not really removed from the database first. So any obsolete collections will stay around, until you delete them, or the database itself. AFAIK loopback will create the db for you, in case it doesn't exist.

raymondfeng commented 10 years ago

@fabien These libraries are interesting:

I also looked at:

Keep in mind, RDBs won't support nested queries.

fabien commented 10 years ago

@raymondfeng sift.js looks good to me, but it doesn't support skip/limit. nedb does, but it seems quite a bit more involved. It can probably be implemented as a new connector altogether.

Users should be made aware of the limits of RDBM's, which is perhaps easiest when having this as a separate connector - so users have to be explicit about it, instead of relying on the memory connector (for tests and so forth) to support any type (both SQL as well as NoSQL style) of query. It's probably easy to copy the mongodb connector's query normalization code and implement this.

Here are some more libraries of interest:

bajtos commented 10 years ago

Loosely related: #683 How can i set condition where on include model

yagobski commented 9 years ago

How this can work for mysql connector? I have same issue

stringbeans commented 9 years ago

Looks like Loopback currently does not support nested include filtering. This seems like a huge limitation. I don't believe the db connector should make any difference because ideally the Loopback framework would work the same regardless of what db connector you're using

weslley39 commented 9 years ago

i'm having the same problem trying to do a nested include. Any solution ?

GameScripting commented 9 years ago

So are there any plans to support nested properties? Is there any way to get the "native" mongodb-connection so we can query the database without the loopback abstraction?

dominikriedel commented 9 years ago

Hey! I've got the Same Problem. I want to query a List of objects based on the property of an related model as well as the property of the wanted model e.g:

Event.find( { where: { and: [ { endDate : { lt : givenDate}}, { location.name : "Abc" }]} }, cb );

So, am I right, that this is not supported atm?

bajtos commented 9 years ago

I want to query a List of objects based on the property of an related model as well as the property of the wanted model. So, am I right, that this is not supported atm?

You are right, this it not supported yet.

dominikriedel commented 9 years ago

so the easiest way would be to just query via SQL? Without any further knowlage: is there any caching mechanism I could use?

pungoyal commented 9 years ago

Can we upvote on this feature?

bajtos commented 9 years ago

Sure, leave a comment containing one of :+1: or +1 (as regular text, not like I did).

pungoyal commented 9 years ago

:+1:

Jeff-Lewis commented 9 years ago

+1

GameScripting commented 9 years ago

+1

weslley39 commented 9 years ago

+1

violet-day commented 9 years ago

:+1:

manlito commented 9 years ago

+1

stringbeans commented 9 years ago

+1

jsam commented 9 years ago

+1

mrbatista commented 9 years ago

+1

raymondfeng commented 9 years ago

I guess we can make it happen for NoSQL DBs, but it will be difficult for RDBs.

rabchev commented 9 years ago

+1

bajtos commented 9 years ago

As far as I am concerned, a good start would be to support nested filters for embedded objects and embedded models.

johnsoftek commented 9 years ago

+1

hotaru355 commented 9 years ago

+1

yagobski commented 9 years ago

+1

AurelieV commented 9 years ago

+1

jbeurel commented 9 years ago

+1

wxqp commented 9 years ago

+1

osunacons commented 9 years ago

+1

bajtos commented 9 years ago

What databases are you using? Is it enough to support filtering on second-level properties for memory and MongoDB, or do you need it for SQL databases too?

bajtos commented 9 years ago

https://github.com/strongloop/loopback-datasource-juggler/pull/544 is adding support for dot-notation to the memory connector, to make it consistent with MongoDB.

This should hopefully fix the issue for @daankets as described in his earlier comment:

Memory in dev, mongo in test and beyond. It's the memory connector that has the issues. We use this one for our dev setup as it resets upon restart... It's the 'dot' notation that is working with mongo.

Implementing this feature for non-embedded relations (e.g. hasMany, belongsTo) and supporting SQL connectors (both embedded and non-embedded relations) requires significant amount of time, which we can't invest right now.

mattiaaccornero commented 9 years ago

+1

daankets commented 9 years ago

Thanks for this! It's making testing quite a bit easier ;-)

sisardor commented 9 years ago

+1

eugenehp commented 9 years ago

:+1:

erikverheij commented 9 years ago

+1

I really love the way PHP's Doctrine ORM has implemented this feature. For some databases filtering takes place on the database level. When a specific database connector does not support the filtering interface Doctrine does the filtering for you using PHP.

http://doctrine-orm.readthedocs.org/en/latest/reference/working-with-associations.html#filtering-collections

I understand it would take a lot of time to provide this feature for all databases, so perhaps it is an option to adapt such a pattern.

jasiedu commented 9 years ago

+1

jgpacheco commented 9 years ago

+1

bryannaegele commented 9 years ago

:+1: