Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
#hash
and #==
for composite pk models
Given a model with a composite primary key, for example: `TravelRoute.primary_key = [:from, :to]` and two objects of the given model, objects `a` and `b`, should be equal to each other and have the same `hash` value if they have the same values for the composite primary key, like: ```ruby a = TravelRoute.new(from: "NYC", to: "LAX") b = TravelRoute.new(from: "NYC", to: "LAX") a == b # => true a.hash == b.hash # => true ``` At the same time, two objects of the given model should not be equal to each other and should have different `hash` values if they have different primary key values or no primary key being set, like: ```ruby a = TravelRoute.new(from: "NYC", to: "LAX") b = TravelRoute.new(from: "NYC", to: "SFO") a == b # => false a.hash == b.hash # => false TravelRoute.new == TravelRoute.new # => false TravelRoute.new.hash == TravelRoute.new.hash # => false ```
- Loading branch information
1 parent
3827576
commit 7b1a617
Showing
4 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters