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

Adding helper method for defaults. #564

Merged
merged 2 commits into from
Dec 14, 2020
Merged

Adding helper method for defaults. #564

merged 2 commits into from
Dec 14, 2020

Conversation

jwoertink
Copy link
Member

Fixes #547

When we merged in #411 this broke the ability to easily set defaults on your query objects.

Before that PR you could do this:

class SomeQuery < User::BaseQuery
  def initialize
    age.gte(21)
  end
end

# WHERE age >= 21
SomeQuery.new

After that PR, you would have to manually set the query object to get the same effect

class SomeQuery < User::BaseQuery
  def initialize
    self.query = age.gte(21).query
  end
end

With this PR, you can still set the query object manually if you want, but this adds in a new defaults method to make it a little more clear on what your intension is. Note that this method is set to private because you shouldn't call this from outside of the query class.

class SomeQuery < User::BaseQuery
  def initialize
    defaults &.age.gte(21)
  end
end

# WHERE age >= 21
SomeQuery.new

Copy link
Member

@matthewmcgarvey matthewmcgarvey left a comment

Choose a reason for hiding this comment

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

🎉

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.

Setting default queries
2 participants