lib/data_miner/attribute.rb in seamusabshere-data_miner-0.1.6 vs lib/data_miner/attribute.rb in seamusabshere-data_miner-0.2.0

- old
+ new

@@ -73,11 +73,15 @@ end def value_as_association(step, value) @_value_as_association ||= {} @_value_as_association[step] ||= {} - @_value_as_association[step][value] ||= reflection_klass(step).send("find_by_#{foreign_key(step)}", value) + if !@_value_as_association[step].has_key?(value) + dynamic_matcher = wants_create?(step) ? "find_or_create_by_#{foreign_key(step)}" : "find_by_#{foreign_key(step)}" + @_value_as_association[step][value] = reflection_klass(step).send(dynamic_matcher, value) + end + @_value_as_association[step][value] end # this will overwrite nils, even if wants_overwriting?(step) is false def set_record_from_row(step, record, row) return if !wants_overwriting?(step) and !record.send(name).nil? @@ -191,11 +195,11 @@ end { :static => 'options_for_step[step].has_key?(:static)', :prefix => :prefix, - :create => 'create(step) != false', + :create => :create, :keep => :keep, :upcase => :upcase, :conversion => '!from(step).nil? or !unit_in_source(step).nil?', :sprintf => :sprintf, :dictionary => :dictionary_options, @@ -245,10 +249,10 @@ reflection.klass end end def wants_inline_association? - !reflection.nil? + reflection.present? end def callback(step) (options_for_step[step][:callback] || "derive_#{name}").to_sym end