-
Notifications
You must be signed in to change notification settings - Fork 190
Bugfix: Allow chaining with same attribute #271
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
Bugfix: Allow chaining with same attribute #271
Conversation
d1b4b9b to
6e89753
Compare
| expect(chained_where_relation.map(&:id)).to eq([1]) | ||
| end | ||
|
|
||
| it "is chainable with same attribute" do |
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.
nice test
lib/active_hash/relation.rb
Outdated
|
|
||
| self.records_dirty = true unless query_hash.nil? || query_hash.keys.empty? | ||
| self.query_hash.merge!(query_hash || {}) | ||
| self.query_list.concat(query_hash&.to_a || []) |
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.
so this is the main bug that this PR is addressing.
The original merge drops the existing keys, the new concat will keep the duplicate keys.
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.
Exactly
kbrock
left a comment
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.
I admit that I am sad to see the hash go away and see the code move towards an array.
It only really shows up as a disadvantage when we are doing a search by id. So I guess it is no big deal.
I just have the one request for update which is minor
Please tweak that and squash your commits and we can merge this.
Remove redundant `|| []` Apply suggestions
eb527ed to
b068b64
Compare
|
Thank you for helping us with this solution. Going with #268 instead |
Expected behavior:
Current behavior: