lib/scaffolding_extensions/model/datamapper.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)
      if reflection.class == DataMapper::Associations::OneToMany::Relationship
        foreign_key = get_key_array_safe(reflection.target_key).name
        table = reflection.target_model
      elsif reflection.class == DataMapper::Associations::ManyToMany::Relationship
        foreign_key = get_key_array_safe(reflection.through.child_key).name
        table = reflection.send(:through_model)
      else
        return
      end
      table.all(foreign_key => from).update(foreign_key => to)
    end
def scaffold_reflection_merge ( reflection , from , to ) if reflection . class == DataMapper :: Associations :: OneToMany :: Relationship foreign_key = get_key_array_safe ( reflection . target_key ) . name table = reflection . target_model elsif reflection . class == DataMapper :: Associations :: ManyToMany :: Relationship foreign_key = get_key_array_safe ( reflection . through . child_key ) . name table = reflection . send ( :through_model ) else return end table . all ( foreign_key => from ) . update ( foreign_key => to ) 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
<not_specific>
from
<not_specific>
to
<not_specific>