Changeset [e97e9af2021660dc422a035468456ddeadd499fc] by snusnu

January 13th, 2011 @ 09:12 PM

Always access relationships in order of definition

This refactoring introduces a few new set classes
that are used to store relationships, properties
and ultimately also descendant sets.

# Implements set behavior and # keeps track of insertion order DataMapper::OrderedSet

# Uses an OrderedSet to keep track of # objects that must respond_to?(:name) DataMapper::SubjectSet "has a" OrderedSet

SubjectSet forms the base class for the already
present DataMapper::PropertySet and the newly added
DataMapper::RelationshipSet.

PropertySet < SubjectSet RelationshipSet < SubjectSet

This makes sure that common behavior between these
two classes is shared, and that RelationshipSet now
remembers the order in which relationships were added
too. Previously, relationships were stored inside a
hash, which would loose order on any not ruby-1.9
implementation.

By using an ordered set to store the relationships,
we can now provide consistent foreign key property
order when automigrating models (or fetching records
using DataMapper::Model#get).

This means that it's finally save to always omit an
explicit property declaration when defining any
relationship either with #belongs_to or #has.
Previously, it wasn't save to call Model#get on
a model with a CPK that consists of FK properties
(a join table). This was because Model#get relies on the key property order which was undefined
before this patch because it simply used a Hash
internally.

[#1398 state:resolved] https://github.com/datamapper/dm-core/commit/e97e9af2021660dc422a03...

Committed by snusnu

  • A lib/dm-core/relationship_set.rb
  • A lib/dm-core/support/ordered_set.rb
  • A lib/dm-core/support/subject_set.rb
  • A spec/unit/data_mapper/ordered_set/append_spec.rb
  • A spec/unit/data_mapper/ordered_set/clear_spec.rb
  • A spec/unit/data_mapper/ordered_set/delete_spec.rb
  • A spec/unit/data_mapper/ordered_set/each_spec.rb
  • A spec/unit/data_mapper/ordered_set/empty_spec.rb
  • A spec/unit/data_mapper/ordered_set/entries_spec.rb
  • A spec/unit/data_mapper/ordered_set/eql_spec.rb
  • A spec/unit/data_mapper/ordered_set/equal_value_spec.rb
  • A spec/unit/data_mapper/ordered_set/hash_spec.rb
  • A spec/unit/data_mapper/ordered_set/include_spec.rb
  • A spec/unit/data_mapper/ordered_set/index_spec.rb
  • A spec/unit/data_mapper/ordered_set/initialize_spec.rb
  • A spec/unit/data_mapper/ordered_set/merge_spec.rb
  • A spec/unit/data_mapper/ordered_set/shared/append_spec.rb
  • A spec/unit/data_mapper/ordered_set/shared/clear_spec.rb
  • A spec/unit/data_mapper/ordered_set/shared/delete_spec.rb
  • A spec/unit/data_mapper/ordered_set/shared/each_spec.rb
  • A spec/unit/data_mapper/ordered_set/shared/empty_spec.rb
  • A spec/unit/data_mapper/ordered_set/shared/entries_spec.rb
  • A spec/unit/data_mapper/ordered_set/shared/include_spec.rb
  • A spec/unit/data_mapper/ordered_set/shared/index_spec.rb
  • A spec/unit/data_mapper/ordered_set/shared/initialize_spec.rb
  • A spec/unit/data_mapper/ordered_set/shared/merge_spec.rb
  • A spec/unit/data_mapper/ordered_set/shared/size_spec.rb
  • A spec/unit/data_mapper/ordered_set/shared/to_ary_spec.rb
  • A spec/unit/data_mapper/ordered_set/size_spec.rb
  • A spec/unit/data_mapper/ordered_set/to_ary_spec.rb
  • A spec/unit/data_mapper/subject_set/append_spec.rb
  • A spec/unit/data_mapper/subject_set/clear_spec.rb
  • A spec/unit/data_mapper/subject_set/delete_spec.rb
  • A spec/unit/data_mapper/subject_set/each_spec.rb
  • A spec/unit/data_mapper/subject_set/empty_spec.rb
  • A spec/unit/data_mapper/subject_set/entries_spec.rb
  • A spec/unit/data_mapper/subject_set/get_spec.rb
  • A spec/unit/data_mapper/subject_set/include_spec.rb
  • A spec/unit/data_mapper/subject_set/named_spec.rb
  • A spec/unit/data_mapper/subject_set/shared/append_spec.rb
  • A spec/unit/data_mapper/subject_set/shared/clear_spec.rb
  • A spec/unit/data_mapper/subject_set/shared/delete_spec.rb
  • A spec/unit/data_mapper/subject_set/shared/each_spec.rb
  • A spec/unit/data_mapper/subject_set/shared/empty_spec.rb
  • A spec/unit/data_mapper/subject_set/shared/entries_spec.rb
  • A spec/unit/data_mapper/subject_set/shared/get_spec.rb
  • A spec/unit/data_mapper/subject_set/shared/include_spec.rb
  • A spec/unit/data_mapper/subject_set/shared/named_spec.rb
  • A spec/unit/data_mapper/subject_set/shared/size_spec.rb
  • A spec/unit/data_mapper/subject_set/shared/to_ary_spec.rb
  • A spec/unit/data_mapper/subject_set/shared/values_at_spec.rb
  • A spec/unit/data_mapper/subject_set/size_spec.rb
  • A spec/unit/data_mapper/subject_set/to_ary_spec.rb
  • A spec/unit/data_mapper/subject_set/values_at_spec.rb
  • M dm-core.gemspec
  • M lib/dm-core.rb
  • M lib/dm-core/associations/relationship.rb
  • M lib/dm-core/collection.rb
  • M lib/dm-core/model.rb
  • M lib/dm-core/model/property.rb
  • M lib/dm-core/model/relationship.rb
  • M lib/dm-core/property_set.rb
  • M lib/dm-core/query.rb
  • M lib/dm-core/query/path.rb
  • M lib/dm-core/resource.rb
  • M lib/dm-core/resource/state.rb
  • M lib/dm-core/spec/shared/public/property_spec.rb
  • M spec/public/model/property_spec.rb
  • M spec/semipublic/property/lookup_spec.rb
  • M spec/semipublic/property_spec.rb
  • M spec/unit/hash_spec.rb
  • M spec/unit/module_spec.rb
New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »