Class DataMapper::Associations::Relationship
In: lib/dm-core/associations/relationship.rb
Parent: Object

Base class for relationships. Each type of relationship (1 to 1, 1 to n, n to m) implements a subclass of this class with methods like get and set overridden.

Methods

Included Modules

Extlib::Assertions

Constants

OPTIONS = [ :child_repository_name, :parent_repository_name, :child_key, :parent_key, :min, :max, :inverse, :reader_visibility, :writer_visibility ].to_set

Attributes

child_properties  [R]  TODO: document @api private
child_repository_name  [R]  Repository from where child objects are loaded

@api semipublic

instance_variable_name  [R]  ivar used to store collection of child options in source

@example for :commits association in

  class VersionControl::Branch
    # ...

    has n, :commits
  end

instance variable name for source will be @commits

@api semipublic

max  [R]  Maximum number of child objects for relationship

@example for :fouls association in

  class Basketball::Player
    # ...

    has 0..5, :fouls
  end

maximum is 5

@api semipublic

min  [R]  Minimum number of child objects for relationship

@example for :cores association in

  class CPU::Multicore
    # ...

    has 2..n, :cores
  end

minimum is 2

@api semipublic

name  [R]  Relationship name

@example for :parent association in

  class VersionControl::Commit
    # ...

    belongs_to :parent
  end

name is :parent

@api semipublic

options  [R]  Options used to set up association of this relationship

@example for :author association in

  class VersionControl::Commit
    # ...

    belongs_to :author, :model => 'Person'
  end

options is a hash with a single key, :model

@api semipublic

parent_properties  [R]  TODO: document @api private
parent_repository_name  [R]  Repository from where parent objects are loaded

@api semipublic

query  [R]  Returns query options for relationship.

For this base class, always returns query options has been initialized with. Overriden in subclasses.

@api private

reader_visibility  [R]  Returns the visibility for the source accessor

@return [Symbol]

  the visibility for the accessor added to the source

@api semipublic

writer_visibility  [R]  Returns the visibility for the source mutator

@return [Symbol]

  the visibility for the mutator added to the source

@api semipublic

Public Class methods

Initializes new Relationship: sets attributes of relationship from options as well as conventions: for instance, @ivar name for association is constructed by prefixing @ to association name.

Once attributes are set, reader and writer are created for the resource association belongs to

@api semipublic

Public Instance methods

Compares another Relationship for equivalency

@param [Relationship] other

  the other Relationship to compare with

@return [Boolean]

  true if they are equal, false if not

@api public

Returns a set of keys that identify the target model

@return [PropertySet]

  a set of properties that identify the target model

@api semipublic

Returns model class used by child side of the relationship

@return [Resource]

  Model for association child

@api private

TODO: document @api private

TODO: document @api private

Eager load the collection using the source as a base

@param [Resource, Collection] source

  the source to query with

@param [Query, Hash] query

  optional query to restrict the collection

@return [Collection]

  the loaded collection for the source

@api private

Compares another Relationship for equality

@param [Relationship] other

  the other Relationship to compare with

@return [Boolean]

  true if they are equal, false if not

@api public

Loads and returns "other end" of the association. Must be implemented in subclasses.

@api semipublic

Gets "other end" of the association directly as @ivar on given resource. Subclasses usually use implementation of this class.

@api semipublic

Get the inverse relationship from the target model

@api semipublic

Checks if "other end" of association is loaded on given resource.

@api semipublic

Returns a set of keys that identify parent model

@return [PropertySet]

  a set of properties that identify parent model

@api private

Returns model class used by parent side of the relationship

@return [Resource]

  Class of association parent

@api private

TODO: document @api private

TODO: document @api private

Creates and returns Query instance that fetches target resource(s) (ex.: articles) for given target resource (ex.: author)

@api semipublic

TODO: document @api private

Sets value of the "other end" of association on given resource. Must be implemented in subclasses.

@api semipublic

Sets "other end" of the association directly as @ivar on given resource. Subclasses usually use implementation of this class.

@api semipublic

Returns a hash of conditions that scopes query that fetches target object

@return [Hash]

  Hash of conditions that scopes query

@api private

Test the source to see if it is a valid target

@param [Object] source

  the resource or collection to be tested

@return [Boolean]

  true if the resource is valid

@api semipulic

[Validate]