lib/scaffolding_extensions/model/active_record.rb
# Updates associated records for a given reflection and from record to point to the
# to record
Updates associated records for a given reflection and from record to point to the
to record
Updates associated records for a given reflection and from record to point to the to record
def scaffold_reflection_merge(reflection, from, to)
      foreign_key = reflection.foreign_key
      sql = case reflection.macro
        when :has_one, :has_many
          return if reflection.options[:through]
          "UPDATE #{reflection.klass.table_name} SET #{foreign_key} = #{to} WHERE #{foreign_key} = #{from}#{" AND #{reflection.options[:as]}_type = #{quote_value(name.to_s)}" if reflection.options[:as]}"
        when :has_and_belongs_to_many
          "UPDATE #{reflection.options[:join_table]} SET #{foreign_key} = #{to} WHERE #{foreign_key} = #{from}" 
        else
          return
      end
      connection.update(sql)
    end
def scaffold_reflection_merge ( reflection , from , to ) foreign_key = reflection . foreign_key sql = case reflection . macro when :has_one , :has_many return if reflection . options [ :through ] "UPDATE #{reflection.klass.table_name} SET #{foreign_key} = #{to} WHERE #{foreign_key} = #{from}#{" AND #{reflection.options[:as]}_type = #{quote_value(name.to_s)}" if reflection.options[:as]}" when :has_and_belongs_to_many "UPDATE #{reflection.options[:join_table]} SET #{foreign_key} = #{to} WHERE #{foreign_key} = #{from}" else return end connection . update ( sql ) end
Updates associated records for a given reflection and from record to point to the
to record
Updates associated records for a given reflection and from record to point to the to record
reflection
from
to