Fix seeding for a first time and duplication on second run
This commit is contained in:
parent
3ed5aa9e10
commit
8256e05d68
|
@ -48,7 +48,7 @@ module SeedFuMongoid
|
||||||
|
|
||||||
def document
|
def document
|
||||||
@doc ||= begin
|
@doc ||= begin
|
||||||
@klass.find_by(constraint_search)
|
@klass.find_by(constraint_search) || @klass.new
|
||||||
rescue => e
|
rescue => e
|
||||||
@klass.new
|
@klass.new
|
||||||
end
|
end
|
||||||
|
@ -58,9 +58,9 @@ module SeedFuMongoid
|
||||||
return @constraint_search if @constraint_search
|
return @constraint_search if @constraint_search
|
||||||
|
|
||||||
@constraint_search = {}
|
@constraint_search = {}
|
||||||
constraints.each do |constraint|
|
@constraints.each do |constraint|
|
||||||
if data[constraint]
|
if data[constraint]
|
||||||
@constraint_search[constraint] = proxy[constraint]
|
@constraint_search[constraint] = data[constraint]
|
||||||
else
|
else
|
||||||
raise ConstraintNotDefined.new(constraint)
|
raise ConstraintNotDefined.new(constraint)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue