lib/spiderfw/model/mappers/db_mapper.rb in spiderfw-0.6.1 vs lib/spiderfw/model/mappers/db_mapper.rb in spiderfw-0.6.2

- old
+ new

@@ -888,21 +888,31 @@ deps << [task, delete_ass] end prev_task = nil set.each do |set_obj| sub_task = MapperTask.new(set_obj, :save) - set_obj.set_modified(element.reverse) if element.reverse if set_obj.class.attributes[:sub_model] && delete_ass set_obj.class.primary_keys.each{ |pk| set_obj.set(pk, nil) } end if prev_task deps << [sub_task, prev_task] - elsif delete_ass - deps << [sub_task, delete_ass] else deps << [sub_task, task] end + if delete_ass + del_dep = set_obj + if element.reverse + set_obj.set_modified(element.reverse) + el = set_obj.class.elements[element.reverse] + # ensure the real owner is added as a dependency + while el.integrated? + del_dep = set_obj.get(el.integrated_from) + el = del_dep.class.elements[el.integrated_from_element] + end + end + deps << [MapperTask.new(del_dep, :save), delete_ass] + end prev_task = sub_task end else el_val.set_modified(element.reverse) deps << [task, MapperTask.new(el_val, :save)] @@ -965,10 +975,14 @@ def storage_column_type(type, attributes) @storage.column_type(type, attributes) end + def storage_column_attributes(type, attributes) + @storage.column_attributes(type, attributes) + end + def base_type(type) if type <= Spider::DataTypes::PK Fixnum else super @@ -996,11 +1010,11 @@ if (!element.model?) column = schema.columns[element.name] storage_type = base_type(element.type) db_attributes = column.attributes if column if (!db_attributes || db_attributes.empty?) - db_attributes = @storage.column_attributes(storage_type, element.attributes) + db_attributes = storage_column_attributes(storage_type, element.attributes) db_attributes.merge(element.attributes[:db]) if (element.attributes[:db]) if (element.attributes[:autoincrement] && !db_attributes[:autoincrement]) schema.set_sequence(element.name, @storage.sequence_name("#{schema.table}_#{element.name}")) end end @@ -1149,10 +1163,10 @@ end end # Returns a create table structure description. def create_table(table_name, schema, attributes) # :nodoc: - fields = schema[:fields_order].map do |f| + fields = schema[:fields_order].uniq.map do |f| details = schema[:columns][f.name] { :name => f.name, :type => details[:type], :attributes => details[:attributes]