Skip to content

Commit

Permalink
fix (Model#update): do not update foreign references
Browse files Browse the repository at this point in the history
  • Loading branch information
vladfaust committed Apr 15, 2019
1 parent ed4323b commit 2b7db58
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/onyx-sql/model/instance_query_shortcuts.cr
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ module Onyx::SQL::Model
changeset.changes!.each do |key, value|
case key
{% for ivar in @type.instance_vars %}
when {{ivar.name.stringify}}
{% if (a = ivar.annotation(Field) || ivar.annotation(Reference)) && a[:not_null] %}
query.set({{ivar.name}}: value.as({{ivar.type}}).not_nil!)
{% else %}
query.set({{ivar.name}}: value.as({{ivar.type}}))
{% unless (a = ivar.annotation(Reference)) && a[:foreign_key] %}
when {{ivar.name.stringify}}
{% if (a = ivar.annotation(Field) || ivar.annotation(Reference)) && a[:not_null] %}
query.set({{ivar.name}}: value.as({{ivar.type}}).not_nil!)
{% else %}
query.set({{ivar.name}}: value.as({{ivar.type}}))
{% end %}
{% end %}
{% end %}
else
Expand Down

0 comments on commit 2b7db58

Please sign in to comment.