Skip to content

Commit

Permalink
chore: prefer not introducing assign_attributes from ActiveModel
Browse files Browse the repository at this point in the history
  • Loading branch information
bf4 committed Jan 22, 2024
1 parent 4e65502 commit 85c067c
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions lib/jsonapi/resource_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1200,16 +1200,12 @@ def define_relationship_methods(relationship_name, relationship_klass, options)
def define_foreign_key_setter(relationship)
if relationship.polymorphic?
define_on_resource "#{relationship.foreign_key}=" do |v|
_model.assign_attributes(
relationship.foreign_key => v[:id],
relationship.polymorphic_type => v[:type]&.to_s&.classify
)
_model.public_send("#{relationship.foreign_key}=", v[:id])
_model.public_send("#{relationship.polymorphic_type}=", v[:type]&.to_s&.classify)
end
else
define_on_resource "#{relationship.foreign_key}=" do |value|
_model.assign_attributes(
relationship.foreign_key => value
)
_model.public_send("#{relationship.foreign_key}=", value)
end
end
relationship.foreign_key
Expand Down

0 comments on commit 85c067c

Please sign in to comment.