Skip to content

Commit df8b680

Browse files
Fix monkey patch of ActiveRecord::Base for records without primary keys
1 parent aceceec commit df8b680

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
- Add official Rails 7.2 support. [#279](https://github.com/splitwise/super_diff/pull/279)
1313
- Add official Rails 8.0 support. [#281](https://github.com/splitwise/super_diff/pull/281)
1414

15+
### Bug fixes
16+
17+
- Fix `attributes_for_super_diff` (in monkey patch of `ActiveRecord::Base`) which would fail for classes that don't have a primary key.
18+
([#282](https://github.com/splitwise/super_diff/pull/282))
19+
1520
### Other changes
1621

1722
- Fix `logger` dependency issues in CI. [#277](https://github.com/splitwise/super_diff/pull/277)

lib/super_diff/active_record/monkey_patches.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def attributes_for_super_diff
77
id_attr = self.class.primary_key
88

99
(attributes.keys.sort - [id_attr]).reduce(
10-
{ id_attr.to_sym => id }
10+
id_attr.nil? ? {} : { id_attr.to_sym => id }
1111
) { |hash, key| hash.merge(key.to_sym => attributes[key]) }
1212
end
1313
end

0 commit comments

Comments
 (0)