Skip to content

Commit

Permalink
feat (Model#update): NilAssertionError with message
Browse files Browse the repository at this point in the history
  • Loading branch information
vladfaust committed Apr 15, 2019
1 parent 2b7db58 commit e1b899c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/onyx-sql/model/instance_query_shortcuts.cr
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ module Onyx::SQL::Model
{% 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!)
if value.nil?
raise NilAssertionError.new("{{@type}}@{{ivar.name}} must not be nil on {{@type}}#update")
else
query.set({{ivar.name}}: value.as({{ivar.type}}).not_nil!)
end
{% else %}
query.set({{ivar.name}}: value.as({{ivar.type}}))
{% end %}
Expand Down

0 comments on commit e1b899c

Please sign in to comment.