# File lib/autumn/datamapper_hacks.rb, line 221
  def child_key(repository_name=nil)
    repository_name ||= repository.name
    @child_key ||= Hash.new
    @child_key[repository_name] ||= begin
      child_key = nil
      repository(repository_name).scope do |r|
        model_properties = child_model.properties(repository_name)

        child_key = parent_key(repository_name).zip(@child_properties || []).map do |parent_property,property_name|
          # TODO: use something similar to DM::NamingConventions to determine the property name
          parent_name = Extlib::Inflection.underscore(Extlib::Inflection.demodulize(parent_model.base_model.name))
          property_name ||= "#{parent_name}_#{parent_property.name}".to_sym

          if model_properties.has_property?(property_name)
            model_properties[property_name]
          else
            options = {}

            [ :length, :precision, :scale ].each do |option|
              options[option] = parent_property.send(option)
            end

            # NOTE: hack to make each many to many child_key a true key,
            # until I can figure out a better place for this check
            if child_model.respond_to?(:many_to_many)
              options[:key] = true
            end

            child_model.property(property_name, parent_property.primitive, options)
          end
        end
      end
      DataMapper::PropertySet.new(child_key)
    end
    return @child_key[repository_name]
  end