Skip to content

Commit

Permalink
Use _read_attribute instead of []
Browse files Browse the repository at this point in the history
It is not only faster, it also doesn't raise an exception if the column
was not fetched in the model using select.
  • Loading branch information
rafaelfranca committed Jan 11, 2021
1 parent 8c60a21 commit 15f6b64
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
Expand Up @@ -111,7 +111,7 @@ def require_counter_update?
def replace_keys(record, force: false)
target_key = record ? record._read_attribute(primary_key(record.class)) : nil

if force || owner[reflection.foreign_key] != target_key
if force || owner._read_attribute(reflection.foreign_key) != target_key
owner[reflection.foreign_key] = target_key
end
end
Expand Down
Expand Up @@ -19,7 +19,7 @@ def replace_keys(record, force: false)

target_type = record ? record.class.polymorphic_name : nil

if force || owner[reflection.foreign_type] != target_type
if force || owner._read_attribute(reflection.foreign_type) != target_type
owner[reflection.foreign_type] = target_type
end
end
Expand Down

0 comments on commit 15f6b64

Please sign in to comment.