From 2b7db58ee603bc25c22319b37ff91bba2990afa9 Mon Sep 17 00:00:00 2001 From: Vlad Faust Date: Mon, 15 Apr 2019 14:19:13 +0300 Subject: [PATCH] fix (Model#update): do not update foreign references --- src/onyx-sql/model/instance_query_shortcuts.cr | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/onyx-sql/model/instance_query_shortcuts.cr b/src/onyx-sql/model/instance_query_shortcuts.cr index 2f021eb..782cc09 100644 --- a/src/onyx-sql/model/instance_query_shortcuts.cr +++ b/src/onyx-sql/model/instance_query_shortcuts.cr @@ -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