Skip to content

Filters through relations#991

Merged
sdepold merged 7 commits intosequelize:masterfrom
snit-ram:filters-throgh-relations
Oct 15, 2013
Merged

Filters through relations#991
sdepold merged 7 commits intosequelize:masterfrom
snit-ram:filters-throgh-relations

Conversation

@snit-ram
Copy link
Copy Markdown
Contributor

Adding support for filtering data through relationships. Good examples of this can be found in the file test/associations/multiple-level-filters.test.js

Here is the added behavior:

Task.findAll({
  where: {
    'project.user.username': 'leia'
  }
}).success(function(tasks){
  //...
});

By running this code, it sequelize will interpret the where clauses adding all the necessary joins to able to run the filter.

Hope you guys like it and consider the merging

@sdepold
Copy link
Copy Markdown
Member

sdepold commented Oct 15, 2013

wow. need to take some further time to review the code :)

@snit-ram
Copy link
Copy Markdown
Contributor Author

I know i'ts big and can seem scary at the first look, but let me give you guys an overview.

  • Theres a lot of new functions to identify this type of filtering and to get the necessary joins
  • hashToWhereConditions, getWhereConditions and selectQuery are the mysql version with minor changes to support the new filtering.
  • I've extracted some database-specific code (like boolean value serialization, select from an array in postgres, and limit & offset) to smaller functions. Due to this change, hashToWhereConditions, getWhereConditions and selectQuery are now the same for every database and was moved to the abstract query generator. That's why you guys see a lot of deletions.

That's it. I tried to follow your code style, so it should not be that difficult to read.

The tests also help to understand the purpose of the change, and are passing in all databases.

If you guys need something from me in order to merge it, please tell me. I'll be glad to help.

@sdepold
Copy link
Copy Markdown
Member

sdepold commented Oct 15, 2013

pretty awesome stuff :)

@sdepold sdepold merged commit 916a803 into sequelize:master Oct 15, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants