Skip to content
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

finding by association doesn't work #5465

Closed
mkeremguc opened this issue Jun 10, 2014 · 13 comments
Closed

finding by association doesn't work #5465

mkeremguc opened this issue Jun 10, 2014 · 13 comments

Comments

@mkeremguc
Copy link

User.js

attributes: {
 groups: {
  collection: 'userGroup',
 }
}

UserGroup.js

attributes: {
 name: {
  type: 'STRING',
 }
}

when i try something like:

User
.find()
.where({groups: [1,2]})
.exec(function(err, user) {
 if (err) {
  res.json({ error: err }, 500);
 } else {
  res.json(user);
 }
});

it gives error:


-error: {
 error: "E_UNKNOWN"
 status: 500
 summary: "Encountered an unexpected error"
-raw: {
 code: "ER_BAD_FIELD_ERROR"
 errno: 1054
 sqlState: "42S22"
 index: 0
}
}

however, i do really need to search via blueprints like posting this to find method of the user controller:

{
 "where": {
   "groups": [1,2]
 }
}

it also gives server error 500 without details.

according to sails issue 124 which was the post about associations, the examples about finding through collections was like that: #124 (comment)

sorry if this is a sails issue and i posted this to wrong place.

using sails v0.10-rc7 and waterline-v0.10-rc13

bug or error on my side ?

thanks

@mkeremguc
Copy link
Author

nooone even uses find by associations?

@luislobo
Copy link
Contributor

luislobo commented Sep 4, 2014

I'm having a similar issue here. Any info on this @mikermcneil?

@tjwebb
Copy link
Contributor

tjwebb commented Sep 7, 2014

Use the latest version of sails. Works for me in 0.10.5

@mkeremguc
Copy link
Author

it still doesn't work for me

@AnalogJ
Copy link

AnalogJ commented Apr 19, 2015

This isn't working for me either in Sails v0.11.0
Is this a verified bug? Or just an unimplemented feature?

@dmarcelino
Copy link
Member

@mkeremguc, @AnalogJ, which adapters are you using?

Regarding .where({groups: [1,2]}), are 1 and 2 primary keys?

@mkeremguc
Copy link
Author

@dmarcelino, mysql and mongo

and yes, primary keys

@AnalogJ
Copy link

AnalogJ commented Apr 20, 2015

@dmarcelino I'm using postgres, and yes, I'm using the primary keys. I didn't catch an error like @mkeremguc saw, my query just never completed, though I just may not have had a .fail() clause set up.

@dmarcelino
Copy link
Member

I'm just thinking... I'm not sure this functionality is in the spec, at least I don't recall it when I implemented sails-orientdb and I don't remember seeing it in the docs. Can someone PR a test to waterline-adapter-tests? That would help towards figuring out which adapters are broken/don't implement this and then we could work on getting it fixed/spec'ed.

@mkeremguc
Copy link
Author

there are lotsa features that is not in the docs either. however, that feature may not be implemented as @dmarcelino said. i was just referencing #124 (comment) at the time.

even though it not be implemented yet, i would still ask how you search/find/filter by association values ? custom in-memory functions would not be efficient for large data sets.

btw, it gives empty array via blueprint at the moment.

@devinivy
Copy link

This often relies on using native (mongo adapter) or query (sql adapters) adapter methods, which allows you to make queries directly through the database wrapper.

@dmarcelino
Copy link
Member

I believe for something like this to work (without resorting to .native() or .query()) we'll need the .populateKeys() feature being discussed in #532 or wait for #266.

@dmarcelino
Copy link
Member

Closing this as duplicate of #266, please re-open if you believe this is a different feature.

@raqem raqem transferred this issue from balderdashy/waterline May 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

6 participants