-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
MONGOID-5608 allow using #exists?
with args on relations
#5736
MONGOID-5608 allow using #exists?
with args on relations
#5736
Conversation
# @return [ true | false ] True is persisted documents exist, false if not. | ||
def exists? | ||
criteria.exists? | ||
def exists?(id_or_conditions = :none) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not:
delegate :exists?, to: :criteria
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would work, too. In general I'm not a fan of that style. It tends to stymie investigation into execution flow, at least for me. I'll think about it, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is recommended by Rubocop: https://docs.rubocop.org/rubocop-rails/cops_rails.html#railsdelegate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
We have now tests for :none
and Hash
. Should we also add tests for nil
and false
?
…5738) * MONGOID-5608 allow using `#exists?` with args on relations * simplify * test the nil/false and _id matching paths, too
Adds extended support for
#exists?
onembeds_many
andhas_many
associations, so the API is the same as is present elsewhere in Mongoid, where the#exists?
accepts conditions that can be used to narrow the scope of the query.