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

Added support for subqueries in Where and Having clauses #1548

Closed
wants to merge 5 commits into from

Conversation

ManReinsp
Copy link

Make sure these boxes checked before submitting your pull request.

  • Do only one thing
  • No API-breaking changes
  • New code/logic commented & tested
  • Write good commit message, try to squash your commits into a single one

What did this pull request do?

Allows developers to use subqueries in the Where and Having clause.
A test is available in the main_test.go:TestQueryBuilderSubselectInWhere function.

Example:

DB.Select("*").Where("age >= ?", DB.
		Select("AVG(age)").Table("users").Subquery()).Find(&users)

@@ -168,6 +168,14 @@ func (s *DB) NewScope(value interface{}) *Scope {
return &Scope{db: dbClone, Search: dbClone.search.clone(), Value: value}
}

// Subquery returns the query as eprx object

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ManReinsp eprx -> expr

jinzhu added a commit that referenced this pull request Aug 11, 2017
@jinzhu
Copy link
Member

jinzhu commented Aug 11, 2017

Hi @ManReinsp

Thank you for your PR and sorry for the delay, I was thinking how to merge those changes w/o replaceParameterPlaceholderLiteral.

Then I have made QueryExpr method (still thinking a better name...) mostly based on your code and test cases.

Thank you.

@jinzhu jinzhu closed this Aug 11, 2017
leocomelli pushed a commit to leocomelli/gorm that referenced this pull request Sep 17, 2017
iahmedov pushed a commit to housinganywhere/gorm that referenced this pull request Sep 3, 2018
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