A shorthand, clear syntax for defining many-to-one resource relationships.
@example [Usage]
* belongs_to :user # many_to_one, :friend * belongs_to :friend, :class_name => 'User' # many_to_one :friends
@param name [Symbol] The name that the association will be referenced by @see has
@return [DataMapper::Association::ManyToOne] The association created
should not be accessed directly
@api public
A shorthand, clear syntax for defining one-to-one, one-to-many and many-to-many resource relationships.
@example [Usage]
* has 1, :friend # one friend * has n, :friends # many friends * has 1..3, :friends # many friends (at least 1, at most 3) * has 3, :friends # many friends (exactly 3) * has 1, :friend, :class_name => 'User' # one friend with the class name User * has 3, :friends, :through => :friendships # many friends through the friendships relationship * has n, :friendships => :friends # identical to above example
@param cardinality [Integer, Range, Infinity]
cardinality that defines the association type and constraints
@param name <Symbol> the name that the association will be referenced by @param opts <Hash> an options hash
@option :through[Symbol] A association that this join should go through to form
a many-to-many association
@option :class_name[String] The name of the class to associate with, if omitted
then the association name is assumed to match the class name
@option :remote_name[Symbol] In the case of a :through option being present, the
name of the relationship on the other end of the :through-relationship to be linked to this relationship.
@return [DataMapper::Association::Relationship] the relationship that was
created to reflect either a one-to-one, one-to-many or many-to-many relationship
@raise [ArgumentError] if the cardinality was not understood. Should be a
Integer, Range or Infinity(n)
@api public
Returns all relationships that are many-to-one for this model.
Used to find the relationships that require properties in any Repository.
Example: class Plur
include DataMapper::Resource def self.default_repository_name :plur_db end repository(:plupp_db) do has 1, :plupp end
end
This resource has a many-to-one to the Plupp resource residing in the :plupp_db repository, but the Plur resource needs the plupp_id property no matter what repository itself lives in, ie we need to create that property when we migrate etc.
Used in DataMapper::Model.properties_with_subclasses
@api private