Skip to content
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

Rails 7.1 compatibility #601

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/composite_primary_keys/persistence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,11 @@ def _delete_record(constraints) # :nodoc:
def _create_record(attribute_names = self.attribute_names)
attribute_names = attributes_for_create(attribute_names)

returning_columns_for_insert = nil

new_id = self.class._insert_record(
attributes_with_values(attribute_names)
attributes_with_values(attribute_names),
returning_columns_for_insert
Copy link
Author

Choose a reason for hiding this comment

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

This seems like a low-effort "fix" from my side.

For reference, upstream changed this from

       new_id = self.class._insert_record(
         attributes_with_values(attribute_names)
       )

       self.id ||= new_id if @primary_key

to

       returning_columns = self.class._returning_columns_for_insert

       returning_values = self.class._insert_record(
         attributes_with_values(attribute_names),
         returning_columns
       )

       returning_columns.zip(returning_values).each do |column, value|
         _write_attribute(column, value) if !_read_attribute(column)
       end if returning_values

)

# CPK
Expand Down
Loading