From 8256e05d68d4b16877717d8457b34cd836da72da Mon Sep 17 00:00:00 2001 From: Sergey Moiseev Date: Tue, 11 Apr 2017 03:05:33 +0300 Subject: [PATCH] Fix seeding for a first time and duplication on second run --- lib/seed-fu-mongoid/document_seeder.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/seed-fu-mongoid/document_seeder.rb b/lib/seed-fu-mongoid/document_seeder.rb index 941cd8c..ebd0774 100644 --- a/lib/seed-fu-mongoid/document_seeder.rb +++ b/lib/seed-fu-mongoid/document_seeder.rb @@ -48,7 +48,7 @@ module SeedFuMongoid def document @doc ||= begin - @klass.find_by(constraint_search) + @klass.find_by(constraint_search) || @klass.new rescue => e @klass.new end @@ -58,9 +58,9 @@ module SeedFuMongoid return @constraint_search if @constraint_search @constraint_search = {} - constraints.each do |constraint| + @constraints.each do |constraint| if data[constraint] - @constraint_search[constraint] = proxy[constraint] + @constraint_search[constraint] = data[constraint] else raise ConstraintNotDefined.new(constraint) end