Closed elrancid closed 8 years ago
@elrancid Thanks for posting, we'll take a look as soon as possible. In the meantime, if you haven’t already, please carefully read the issue contribution guidelines and double-check for any missing information above. In particular, please ensure that this issue is about a stability or performance bug with a documented feature; and make sure you’ve included detailed instructions on how to reproduce the bug from a clean install. Finally, don’t forget to include the version of Node.js you tested with, as well as your version of Sails or Waterline, and of any relevant standalone adapters/generators/hooks.
Thank you!
Hi @elrancid, it looks like you're trying to do something that's just not supported by Waterline. Waterline does not currently allow you to reference associations inside of queries -- that is, it doesn't create subqueries for you. It's definitely something we want for the next major version, but in the meantime if you need queries like "Give me the union of all users named 'Bob' and all users with brown pets", you'll either need to use .query
to do a native MySQL query, or do two queries and combine the results.
I've found a bug making query with foreign key with name different from the referenced table. The bug occurs, for example, with a query like this:
In this example
othertable
is a foreign key property to a table with the name different from "othertable", in example:I've partially solved the issues in waterline-sequel/sequel/lib/criteriaProcessor.js in findChild() function:
If there is a foreign key, the definitionKey in
findChild
function returns the name of the property, but "findChild" is used in "processObject()->expandCriteria()" function:and
child
(= findChild(parent)
) is used to set thetableScope
in order to save the table name referenced by the foreign key (to make the query).findChild
must return the table name (or the table name must be grabbed beforeself.tableScope = child;
). If the property has the same name of the table name (referenced by foreign key), then this bug doesn't occurs (because the name is the same). I've found it because I've the property name different from the table name. I've resolved, for now, changing the return offindChild
:However, this solution can't be considered completely correct because it returns the model name, not the table name. So, if the table name is different from the model name, we must get the real table name from the model. I don't know much about this module works, so I don't know how to achieve this task.