Skip to content

Association filtering and inner join#1199

Merged
mickhansen merged 5 commits intosequelize:masterfrom
mickhansen:association-filtering
Jan 4, 2014
Merged

Association filtering and inner join#1199
mickhansen merged 5 commits intosequelize:masterfrom
mickhansen:association-filtering

Conversation

@mickhansen
Copy link
Copy Markdown
Contributor

Makes it possible to force a INNER JOIN by setting required: true as a option to include:

Project.findAll({
  include: [
    {model: User, required: true}}
  ]
})
// SELECT * FROM project INNER JOIN user ON project.user_id = user.id 

If there is a where condition on the include it will be required: true by default.

Project.findAll({
  include: [
    {model: User, where: {last_name: 'Hansen'}}
  ]
})
// SELECT * FROM project INNER JOIN user ON project.user_id = user.id AND user.last_name = 'Hansen'

mickhansen added a commit that referenced this pull request Jan 4, 2014
@mickhansen mickhansen merged commit ad7ec9a into sequelize:master Jan 4, 2014
@mickhansen mickhansen deleted the association-filtering branch January 4, 2014 23:09
@JohannesBeranek
Copy link
Copy Markdown

just commenting in case someone else finds this: reading the source it's
required ? 'INNER JOIN' : 'LEFT OUTER JOIN'

@mickhansen
Copy link
Copy Markdown
Contributor Author

@griffin1987 good catch, i made a typo which i've corrected now.

@davidrapin
Copy link
Copy Markdown
Contributor

@JohannesBeranek thank you !!

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.

3 participants