Add exists? to Relation#349
Conversation
ActiveRecord allows calling exists? on Realtions, however ActiveHash currently only allows calling it on the base model. Adding the method to Realtion provides functionality that those familar with ActiveRecord expect.
|
@michebble We'd welcome a pull request for this, if you're up for it! |
|
Thank you @flavorjones . I have updated the comment to make it clear what this PR changes. |
kbrock
left a comment
There was a problem hiding this comment.
This looks great.
curious, did you try delegating exist? to :records?
.e.g.:
module ActiveHash
class Relation
# about line 8
delegate :sample, :exists?, to: :records
end
endor updating one of the entries there.
try it out, and then ping if you have any issues.
This code is ok, but if you notice, we tried to avoid duplicating the method definitions
We can use the Relation implementation of exists? and then delegate the method on Base. This will give us one implementation that can be used on but the record class or a scoped relation.
|
I was hoping it would be that simple at first, but I believe this matches the spirit of your suggestion and the specs are still green. Thank you for the comment. |
This PR adds exists? to
Relationso that users can call the method after applying a scope to an ActiveHash model.This brings the behaviour inline with ActiveRecord.
Problem
Calling
exists?after apply scope/s results in NoMethodError being raised.Without PR changes
With PR changes
initial comment