-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Filter on level 2 properties #517
Comments
Which connector are you using? |
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. |
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 |
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 ;-) |
Of course - however, you can easily reset the test database before you start, like this:
|
Will this drop the entire schema? |
Yes, but in the case of MongoDB collections will be empties and indexes re-created. There's no real schema, like with SQL databases. |
Sure. Just calling it a 'schema' as a 'habit' |
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. |
@fabien These libraries are interesting: I also looked at: Keep in mind, RDBs won't support nested queries. |
@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:
|
Loosely related: #683 How can i set condition where on include model |
How this can work for mysql connector? I have same issue |
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 |
i'm having the same problem trying to do a nested include. Any solution ? |
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? |
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? |
You are right, this it not supported yet. |
so the easiest way would be to just query via SQL? Without any further knowlage: is there any caching mechanism I could use? |
Can we upvote on this feature? |
Sure, leave a comment containing one of |
👍 |
in the doc i can read: so a query like this it's impossible on mysql i can't see any valid workarount to achieve multiple join with where condition... that will require multiple queries leading performance issues (and resource waste) any suggestion? |
I am lost at the moment. This ticket is closed, but does filtering on nested properties work with mongodb? |
@F3L1X79 It works as long as the nested properties are embedded on the same document. |
This does not work for MySQL. It should be possible to translate something like: User.find({where: {'address.tags.tag': 'business'}} Into Can someone point me in the direction of the code where the translation from JSON to SQL is done? Thanks. |
@acrodrig I think most of the code you're looking for will be here: https://github.com/strongloop/loopback-connector-mysql/blob/master/lib/mysql.js. |
Also for anyone interested - there is support for this to some degree in postrgres using the json data type as per this PR |
Why the filter with property id does not work? If I change it to any other property name it works (ie: customer.name). I'm using mongodb connector.
|
Hey @elviocb , this must be problem with customer.id stored as String and not ObjectId. Can you share how your Order model looks. It should be related to https://loopback.io/doc/ja/lb3/MongoDB-connector.html#strictobjectidcoercion-flag |
hey @princecharmx .. thanks for your reply! That's my order model definition:
And this is how an order model is stored:
|
You have incorrect model. You are having property customer and also have a relation customers with hasOne. Also, as pointed note, your customer.id is stored as string and hence you are having problem.
Fyi, your usage is incorrect at many places. First you confirm if my suggestion works. I will then guide you next steps. |
Hey @princecharmx .. It works. Thanks!.. Could you guide me which other parts of the model are incorrect please? |
I can't see valid solution for MYSQL inner join yet, has anyone found at least a workaround? |
I've made a fork of loopback-connector-mysql to support joins. It's not an ideal solution but it works, I'm using it in production in my applications. It only supports read operations. This is a filter working over the User built-in model, to find all users with an ADMIN name role (the relation between User and Role is needed):
You can check it out https://github.com/jolivervidal/loopback-connector-mysql |
@jolivervidal just tested and that work perfectly !!! you save me a lot of time, why this is not included in the standard library? i'll check what you have done in your fork! |
Right now we have a workaround solution for this case ? :( for mongoDB |
@bellgetlinks For mongodb I've ended up opening a connection to mongodb in a boot script and running direct queries and filters on related models using I found this stack overflow post helpful for including related documents in queries. This is the boot script I used to connect to mongodb and expose it as
|
@jolivervidal |
What's the status of this issue? Seems a very important feature is missing. @jolivervidal your fork seems working very well, why not merging with the master branch? |
@michelgokan as you'll see from the thread:
Options are:
|
Thanks, @zbarbuto but none of your mentioned alternatives works, at least
for me at the moment:
1. I can’t write custom SQL scripts/custom endpoints as it ruins the whole
architecture of my application (but maybe the most usable solution at the
moment!!!!!)
2. For the same reason, it's not possible to use Bookshelf or Knex
3. Then we should basically ignore the whole idea behind using relational
DBs: to be able to perform complex queries!!
4. Same as 3
5. This feature is not working even in Loopback 4, so can't see a point for
migration.
I didn't find a problem in @jolivervidal fork at the moment. I hope nothing
bad happens 😬
…On Sun, 3 Mar 2019 at 23:43, zbarbuto ***@***.***> wrote:
@michelgokan <https://github.com/michelgokan> as you'll see from the
thread:
- There is some support in postgres connector
<#517 (comment)>
- Mongo also has some basic support (only for dot nested properties)
- Further support isn't going to be added to other RDB connectors as
loopback 3 is in LTS and no longer accepting new feature PRs
- Loopback 3 ends LTS at the end of 2019 so it's even less likely to
be added.
Options are:
- Write the custom SQL yourself as a custom endpoint
- Create an alternate connector for something like Knex
<https://knexjs.org/> or Bookshelf <https://bookshelfjs.org/> that has
support (big job)
- Do the filtering in memory
- Use json for the nested data to use dot queries in something like
mongo or postgres
- Look at migrating to loopback next which may add support in the
future
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#517 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AARH6W9n5vY5vqmX9fyotI6573Hl__nfks5vTFArgaJpZM4Ccngj>
.
|
Does anyone know if the loopback datasource is compatible with the knex connector? It'd be great to use the same connections for both, to migrate to knex if possible. Then wrap around something like objection.js for filtering on nested relations. |
@jeff3yan You'd have to write your own loopback-knex-connector. I've tried a few times but it's a big job and never really got anywhere with it. Having said that it would be an amazingly useful took if someone did manage to crack it. Particularly since join style queries ( @michelgokan if that fork is working for you with MySQL then sounds like a good solution. I agree it's an unfortunate situation for users of other RDBs (like Postgres) but it's just the way loopback works - it does not assume your models are in any particular datasource so it does not leverage the full power of the underlying datasource (you may be querying two models in postgres or one might be in postgres and one might be in Mongo - it makes no assumptions) |
@tellex solution works very well for PostgreSQL. Thank you so much! Code and instructions: |
For those who are using PostgreSQL I'm using @tellex solution, and it's working greate on a large project. |
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?
The text was updated successfully, but these errors were encountered: