def reflect_on_all_associations klass
        klass.relationships.collect do |relationship|
          # All can be child/parent
          # ManyToMany
          # ManyToOne
          # OneToMany
          # OneToOne
          #TODO :has_and_belongs_to_many
          if relationship.kind_of?(::DataMapper::Associations::ManyToOne::Relationship) && relationship.child_model? #relationship.options[:min] == 1 && relationship.options[:max] == 1
            macro = :belongs_to
            if relationship.options[:class_name]
              # In a belongs_to, the side with the class name uses
              # the parent model, but child key for the foreign key...
              class_name = relationship.parent_model.to_s
              primary_key_name = relationship.child_key.entries.first.name
            else
              class_name = relationship.child_model.to_s
              primary_key_name = relationship.parent_key.entries.first.name
            end
          else
            macro = :has_one
            if relationship.options[:class_name]
              # but on the has_one side, it's the *child* model that
              # uses the child key for the foreign key.  Weirdness.
              class_name = relationship.child_model.to_s
              primary_key_name = relationship.child_key.entries.first.name
            else
              class_name = relationship.parent_model.to_s
              primary_key_name = relationship.parent_key.entries.first.name
            end
          end
          OpenStruct.new(
            :name => relationship.name,
            :options => {
              #:foreign_key => , # Ignore, let the calling code infer: {name}_id
              :polymorphic => false # Hard code for now
            },
            :class_name => class_name,
            :primary_key_name => primary_key_name,
            :macro => macro
          )
        end
      end
def reflect_on_all_associations klass
        klass.relationships.collect do |relationship|
          # All can be child/parent
          # ManyToMany
          # ManyToOne
          # OneToMany
          # OneToOne
          #TODO :has_and_belongs_to_many
          if relationship.kind_of?(::DataMapper::Associations::ManyToOne::Relationship) && relationship.child_model? #relationship.options[:min] == 1 && relationship.options[:max] == 1
            macro = :belongs_to
            if relationship.options[:class_name]
              # In a belongs_to, the side with the class name uses
              # the parent model, but child key for the foreign key...
              class_name = relationship.parent_model.to_s
              primary_key_name = relationship.child_key.entries.first.name
            else
              class_name = relationship.child_model.to_s
              primary_key_name = relationship.parent_key.entries.first.name
            end
          else
            macro = :has_one
            if relationship.options[:class_name]
              # but on the has_one side, it's the *child* model that
              # uses the child key for the foreign key.  Weirdness.
              class_name = relationship.child_model.to_s
              primary_key_name = relationship.child_key.entries.first.name
            else
              class_name = relationship.parent_model.to_s
              primary_key_name = relationship.parent_key.entries.first.name
            end
          end
          OpenStruct.new(
            :name => relationship.name,
            :options => {
              #:foreign_key => , # Ignore, let the calling code infer: {name}_id
              :polymorphic => false # Hard code for now
            },
            :class_name => class_name,
            :primary_key_name => primary_key_name,
            :macro => macro
          )
        end
      end
http://pastie.org/pastes/233178
 Semi-equivalent of ActiveRecord's reflect_on_all_associations method