Skip to content

Commit

Permalink
feat: add support of polymorphic association for create entity
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasalexandre9 committed Dec 20, 2023
1 parent bfdbe87 commit ea1d776
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/deserializers/forest_liana/resource_deserializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ def extract_relationships
# ActionController::Parameters do not inherit from Hash anymore
# since Rails 5.
if (data.is_a?(Hash) || data.is_a?(ActionController::Parameters)) && data[:id]
@attributes[name] = association.klass.find(data[:id])
if (SchemaUtils.polymorphic?(association))
@attributes[association.foreign_key] = data[:id]
@attributes[association.foreign_type] = data[:type]
else
@attributes[name] = association.klass.find(data[:id])
end
elsif data.blank?
@attributes[name] = nil
end
Expand Down

0 comments on commit ea1d776

Please sign in to comment.