Skip to content

Commit 2b7db58

Browse files
committed
fix (Model#update): do not update foreign references
1 parent ed4323b commit 2b7db58

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

src/onyx-sql/model/instance_query_shortcuts.cr

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,13 @@ module Onyx::SQL::Model
5555
changeset.changes!.each do |key, value|
5656
case key
5757
{% for ivar in @type.instance_vars %}
58-
when {{ivar.name.stringify}}
59-
{% if (a = ivar.annotation(Field) || ivar.annotation(Reference)) && a[:not_null] %}
60-
query.set({{ivar.name}}: value.as({{ivar.type}}).not_nil!)
61-
{% else %}
62-
query.set({{ivar.name}}: value.as({{ivar.type}}))
58+
{% unless (a = ivar.annotation(Reference)) && a[:foreign_key] %}
59+
when {{ivar.name.stringify}}
60+
{% if (a = ivar.annotation(Field) || ivar.annotation(Reference)) && a[:not_null] %}
61+
query.set({{ivar.name}}: value.as({{ivar.type}}).not_nil!)
62+
{% else %}
63+
query.set({{ivar.name}}: value.as({{ivar.type}}))
64+
{% end %}
6365
{% end %}
6466
{% end %}
6567
else

0 commit comments

Comments
 (0)