Skip to content

Commit

Permalink
Merge pull request #96 from metacortex/master
Browse files Browse the repository at this point in the history
#95 use 'first?' to prevent 'IndexError' when insert/update
  • Loading branch information
fridgerator authored Jun 1, 2017
2 parents a46c033 + 9cca1f3 commit 42dca74
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/crecto/repo.cr
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ module Crecto
changeset.add_error("insert_error", "Insert Failed")
elsif config.adapter == Crecto::Adapters::Postgres || (config.adapter == Crecto::Adapters::Mysql && tx.nil?) ||
(config.adapter == Crecto::Adapters::SQLite3 && tx.nil?)
new_instance = changeset.instance.class.from_rs(query.as(DB::ResultSet)).first
new_instance = changeset.instance.class.from_rs(query.as(DB::ResultSet)).first?
changeset = new_instance.class.changeset(new_instance) if new_instance
end

Expand Down Expand Up @@ -220,7 +220,7 @@ module Crecto
if query.nil?
changeset.add_error("update_error", "Update Failed")
else
new_instance = changeset.instance.class.from_rs(query.as(DB::ResultSet)).first
new_instance = changeset.instance.class.from_rs(query.as(DB::ResultSet)).first?
changeset = new_instance.class.changeset(new_instance) if new_instance
end

Expand Down

0 comments on commit 42dca74

Please sign in to comment.