anchor.diff:    col_name = entity.sync.master_entity.attribute_by_name(a.name).referenced_entity.primary_key.sql.quoted_column_name
     ref_prefix = "R#{reference_index}"
     if a.referenced_entity.abstract?
  -    s = a.referenced_entity.subtypes.select{|a| !a.abstract? }.size
  +    s = a.referenced_entity.subtypes.select{|st| !st.abstract? }.size
       cols = (0...(s)).collect do |index|
         "#{ref_prefix}#{index}.#{col_name}"
       end.join(", ")
  
positive.code:       col_name = entity.sync.master_entity.attribute_by_name(a.name).referenced_entity.primary_key.sql.quoted_column_name
        ref_prefix = "R#{reference_index}"
        if a.referenced_entity.abstract?
          s = a.referenced_entity.subtypes.select{|a| !a.abstract? }.size
          cols = (0...(s)).collect do |index|
            "#{ref_prefix}#{index}.#{col_name}"
          end.join(", ")
  
negative.code: <% if a.referenced_entity.name == entity.name -%>
            " LEFT JOIN <%= entity.sync.sync_temp_entity.sql.qualified_table_name %> AS O ON O.<%= entity.sync.sync_temp_entity.attribute_by_name(:MappingID).sql.quoted_column_name %> = S.<%= entity.sync.sync_temp_entity.attribute_by_name("#{a.name}MappingID").sql.quoted_column_name %> AND O.<%= entity.sync.master_entity.attribute_by_name(:MappingSource).sql.quoted_column_name %> = S.<%= entity.sync.sync_temp_entity.attribute_by_name(:MappingSource).sql.quoted_column_name %>" +
  <% elsif a.referenced_entity.abstract? -%>
  <% a.referenced_entity.subtypes.select{|st| !st.abstract? }.each_with_index do |subtype, index| -%>
            " LEFT JOIN <%= subtype.sync.master_entity.sql.qualified_table_name %> AS O<%= index %> ON O<%= index %>.<%= subtype.sync.master_entity.attribute_by_name(:MappingID).sql.quoted_column_name %> = S.<%= entity.sync.sync_temp_entity.attribute_by_name("#{a.name}MappingID").sql.quoted_column_name %> AND O<%= index %>.<%= subtype.sync.master_entity.attribute_by_name(:MappingSource).sql.quoted_column_name %> = S.<%= entity.sync.sync_temp_entity.attribute_by_name(:MappingSource).sql.quoted_column_name %> AND O<%= index %>.<%= subtype.sync.master_entity.attribute_by_name(:DeletedAt).sql.quoted_column_name %> IS NULL" +
  <% end -%>
  <% else -%>
  