Skip to content

Commit

Permalink
quick fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Bob committed Nov 14, 2024
1 parent bb1a01b commit 0d96dec
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/avo/fields/belongs_to_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def primary_key
@primary_key ||= reflection.association_primary_key
# Quick fix for "Polymorphic associations do not support computing the class."
rescue
id
nil
end

def foreign_key
Expand Down Expand Up @@ -218,12 +218,22 @@ def fill_field(record, key, value, params)
if valid_model_class.blank? || id_from_param.blank?
record.send(:"#{polymorphic_as}_id=", nil)
else
record_id = target_resource(record:, polymorphic_model_class: value.safe_constantize).find_record(id_from_param).send(primary_key)
record = target_resource(record:, polymorphic_model_class: value.safe_constantize).find_record(id_from_param)
record_id = if primary_key.present?
record.send(primary_key)
else
record.id
end

record.send(:"#{polymorphic_as}_id=", record_id)
end
else
record_id = value.blank? ? value : target_resource(record:).find_record(value).send(primary_key)
record = value.blank? ? value : target_resource(record:).find_record(value)
record_id = if primary_key.present?
record.send(primary_key)
else
record.id
end

record.send(:"#{key}=", record_id)
end
Expand Down

0 comments on commit 0d96dec

Please sign in to comment.