Module DataMapper::Model
In: lib/dm-core/model.rb
lib/dm-core/model/scope.rb
lib/dm-core/model/is.rb
lib/dm-core/model/hook.rb
lib/dm-core/model/property.rb
lib/dm-core/model/relationship.rb

Methods

Included Modules

Enumerable Scope Is

Classes and Modules

Module DataMapper::Model::Hook
Module DataMapper::Model::Is
Module DataMapper::Model::Property
Module DataMapper::Model::Relationship
Module DataMapper::Model::Scope

Constants

WRITER_METHOD_REGEXP = /=\z/.freeze
INVALID_WRITER_METHODS = %w[ == != === []= taguri= attributes= collection= persistence_state= raise_on_save_failure= ].to_set.freeze

Attributes

allowed_writer_methods  [R]  The list of writer methods that can be mass-assigned to in attributes=

@return [Set]

@api private

base_model  [R]  @api semipublic

Public Class methods

Extends the model with this module after Resource has been included.

This is a useful way to extend Model while still retaining a self.extended method.

@param [Module] extensions

  List of modules that will extend the model after it is extended by Model

@return [Boolean]

  whether or not the inclusions have been successfully appended to the list

@api semipublic

Appends a module for inclusion into the model class after Resource.

This is a useful way to extend Resource while still retaining a self.included method.

@param [Module] inclusions

  the module that is to be appended to the module after Resource

@return [Boolean]

  true if the inclusions have been successfully appended to the list

@api semipublic

Return all models that extend the Model module

  class Foo
    include DataMapper::Resource
  end

  DataMapper::Model.descendants.first   #=> Foo

@return [DescendantSet]

  Set containing the descendant models

@api semipublic

The current registered extra extensions

@return [Set]

@api private

The current registered extra inclusions

@return [Set]

@api private

Creates a new Model class with its constant already set

If a block is passed, it will be eval‘d in the context of the new Model

@param [to_s] name

  the name of the new model

@param [Object] namespace

  the namespace that will hold the new model

@param [Proc] block

  a block that will be eval'd in the context of the new Model class

@return [Model]

  the newly created Model class

@api private

Return if Resource#save should raise an exception on save failures (globally)

This is false by default.

  DataMapper::Model.raise_on_save_failure  # => false

@return [Boolean]

  true if a failure in Resource#save should raise an exception

@api public

Specify if Resource#save should raise an exception on save failures (globally)

@param [Boolean]

  a boolean that if true will cause Resource#save to raise an exception

@return [Boolean]

  true if a failure in Resource#save should raise an exception

@api public

Public Instance methods

Find a set of records matching an optional set of conditions. Additionally, specify the order that the records are return.

  Zoo.all                                   # all zoos
  Zoo.all(:open => true)                    # all zoos that are open
  Zoo.all(:opened_on => start..end)         # all zoos that opened on a date in the date-range
  Zoo.all(:order => [ :tiger_count.desc ])  # Ordered by tiger_count

@param [Hash] query

  A hash describing the conditions and order for the query

@return [Collection]

  A set of records found matching the conditions in +query+

@see Collection

@api public

Copy a set of records from one repository to another.

@param [String] source_repository_name

  The name of the Repository the resources should be copied _from_

@param [String] target_repository_name

  The name of the Repository the resources should be copied _to_

@param [Hash] query

  The conditions with which to find the records to copy. These
  conditions are merged with Model.query

@return [Collection]

  A Collection of the Resource instances created in the operation

@api public

Create a Resource

@param [Hash(Symbol => Object)] attributes

  attributes to set

@return [Resource]

  the newly created Resource instance

@api public

Create a Resource, bypassing hooks

@param [Hash(Symbol => Object)] attributes

  attributes to set

@return [Resource]

  the newly created Resource instance

@api public

Return all models that inherit from a Model

  class Foo
    include DataMapper::Resource
  end

  class Bar < Foo
  end

  Foo.descendants.first   #=> Bar

@return [Set]

  Set containing the descendant classes

@api semipublic

Remove all Resources from the repository

@return [Boolean]

  true if the resources were successfully destroyed

@api public

Remove all Resources from the repository, bypassing validation

@return [Boolean]

  true if the resources were successfully destroyed

@api public

Finish model setup and verify it is valid

@return [undefined]

@api public

Return the first Resource or the first N Resources for the Model with an optional query

When there are no arguments, return the first Resource in the Model. When the first argument is an Integer, return a Collection containing the first N Resources. When the last (optional) argument is a Hash scope the results to the query.

@param [Integer] limit (optional)

  limit the returned Collection to a specific number of entries

@param [Hash] query (optional)

  scope the returned Resource or Collection to the supplied query

@return [Resource, Collection]

  The first resource in the entries of this collection,
  or a new collection whose query has been merged

@api public

Finds the first Resource by conditions, or creates a new Resource with the attributes if none found

@param [Hash] conditions

  The conditions to be used to search

@param [Hash] attributes

  The attributes to be used to create the record of none is found.

@return [Resource]

  The instance found by +query+, or created with +attributes+ if none found

@api public

Finds the first Resource by conditions, or initializes a new Resource with the attributes if none found

@param [Hash] conditions

  The conditions to be used to search

@param [Hash] attributes

  The attributes to be used to create the record of none is found.

@return [Resource]

  The instance found by +query+, or created with +attributes+ if none found

@api public

Grab a single record by its key. Supports natural and composite key lookups as well.

  Zoo.get(1)                # get the zoo with primary key of 1.
  Zoo.get!(1)               # Or get! if you want an ObjectNotFoundError on failure
  Zoo.get('DFW')            # wow, support for natural primary keys
  Zoo.get('Metro', 'DFW')   # more wow, composite key look-up

@param [Object] *key

  The primary key or keys to use for lookup

@return [Resource, nil]

  A single model that was found
  If no instance was found matching +key+

@api public

Grab a single record just like get, but raise an ObjectNotFoundError if the record doesn‘t exist.

@param [Object] *key

  The primary key or keys to use for lookup

@return [Resource]

  A single model that was found

@raise [ObjectNotFoundError]

  The record was not found

@api public

Return the last Resource or the last N Resources for the Model with an optional query

When there are no arguments, return the last Resource for the Model. When the first argument is an Integer, return a Collection containing the last N Resources. When the last (optional) argument is a Hash scope the results to the query.

@param [Integer] limit (optional)

  limit the returned Collection to a specific number of entries

@param [Hash] query (optional)

  scope the returned Resource or Collection to the supplied query

@return [Resource, Collection]

  The last resource in the entries of this collection,
  or a new collection whose query has been merged

@api public

Loads an instance of this Model, taking into account IdentityMap lookup, inheritance columns(s) and Property typecasting.

@param [Enumerable(Object)] records

  an Array of Resource or Hashes to load a Resource with

@return [Resource]

  the loaded Resource instance

@api semipublic

Return if Resource#save should raise an exception on save failures (per-model)

This delegates to DataMapper::Model.raise_on_save_failure by default.

  User.raise_on_save_failure  # => false

@return [Boolean]

  true if a failure in Resource#save should raise an exception

@api public

Specify if Resource#save should raise an exception on save failures (per-model)

@param [Boolean]

  a boolean that if true will cause Resource#save to raise an exception

@return [Boolean]

  true if a failure in Resource#save should raise an exception

@api public

Gets the current Set of repositories for which this Model has been defined (beyond default)

@return [Set]

  The Set of repositories for which this Model
  has been defined (beyond default)

@api private

Get the repository with a given name, or the default one for the current context, or the default one for this class.

@param [Symbol] name

  the name of the repository wanted

@param [Block] block

  block to execute with the fetched repository as parameter

@return [Object, Respository]

  whatever the block returns, if given a block,
  otherwise the requested repository.

@api private

Get the current repository_name for this Model.

If there are any Repository contexts, the name of the last one will be returned, else the default_repository_name of this model will be

@return [String]

  the current repository name to use for this Model

@api private

slice(*args)

Alias for #[]

Gets the name of the storage receptacle for this resource in the given Repository (ie., table name, for database stores).

@return [String]

  the storage name (ie., table name, for database stores) associated with
  this resource in the given repository

@api public

the names of the storage receptacles for this resource across all repositories

@return [Hash(Symbol => String)]

  All available names of storage receptacles

@api public

Update every Resource

  Person.update(:allow_beer => true)

@param [Hash] attributes

  attributes to update with

@return [Boolean]

  true if the resources were successfully updated

@api public

Update every Resource, bypassing validations

  Person.update!(:allow_beer => true)

@param [Hash] attributes

  attributes to update with

@return [Boolean]

  true if the resources were successfully updated

@api public

[Validate]