lib/lotus/model/mapping/coercer.rb in lotus-model-0.2.4 vs lib/lotus/model/mapping/coercer.rb in lotus-model-0.3.0
- old
+ new
@@ -58,16 +58,18 @@
instance_eval <<-EVAL, __FILE__, __LINE__
def to_record(entity)
if entity.id
Hash[#{ @collection.attributes.map{|name,(klass,mapped)| ":#{mapped},Lotus::Model::Mapping::Coercions.#{klass}(entity.#{name})"}.join(',') }]
else
- Hash[#{ @collection.attributes.reject{|name,_| name == @collection.identity }.map{|name,(klass,mapped)| ":#{mapped},Lotus::Model::Mapping::Coercions.#{klass}(entity.#{name})"}.join(',') }]
+ Hash[].tap do |record|
+ #{ @collection.attributes.reject{|name,_| name == @collection.identity }.map{|name,(klass,mapped)| "value = Lotus::Model::Mapping::Coercions.#{klass}(entity.#{name}); record[:#{mapped}] = value unless value.nil?"}.join('; ') }
+ end
end
end
def from_record(record)
- #{ @collection.entity }.new(
+ ::#{ @collection.entity }.new(
Hash[#{ @collection.attributes.map{|name,(klass,mapped)| ":#{name},Lotus::Model::Mapping::Coercions.#{klass}(record[:#{mapped}])"}.join(',') }]
)
end
#{ code }
@@ -75,6 +77,5 @@
end
end
end
end
end
-