Skip to content

Conversation

@gastronleroux
Copy link

Expected behavior:

Country.where(id: 1).where(id: 2) # []

Current behavior:

Country.where(id: 1).where(id: 2) # [#< Country id=2>]

@gastronleroux gastronleroux force-pushed the fix-chaining-with-same-attribute branch 3 times, most recently from d1b4b9b to 6e89753 Compare January 16, 2023 18:46
expect(chained_where_relation.map(&:id)).to eq([1])
end

it "is chainable with same attribute" do
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice test

@gastronleroux gastronleroux requested a review from kbrock January 17, 2023 22:53

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 || [])
Copy link
Collaborator

@kbrock kbrock Jan 18, 2023

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.

Copy link
Author

Choose a reason for hiding this comment

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

Exactly

Copy link
Collaborator

@kbrock kbrock left a 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
@kbrock
Copy link
Collaborator

kbrock commented Mar 27, 2023

Thank you for helping us with this solution. Going with #268 instead

@kbrock kbrock closed this Mar 27, 2023
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.

2 participants