File: README.rdoc [dm-constraints-1.2.0 Documentation]

### Home Classes Methods

### Files

- LICENSE
- README.rdoc

### Class Index

Quicksearch

- DataMapper
- DataMapper::Constraints
- DataMapper::Constraints::Adapters
- DataMapper::Constraints::Adapters::AbstractAdapter
- DataMapper::Constraints::Adapters::DataObjectsAdapter
- DataMapper::Constraints::Adapters::DataObjectsAdapter::SQL
- DataMapper::Constraints::Adapters::Extension
- DataMapper::Constraints::Adapters::MysqlAdapter
- DataMapper::Constraints::Adapters::MysqlAdapter::SQL
- DataMapper::Constraints::Adapters::OracleAdapter
- DataMapper::Constraints::Adapters::PostgresAdapter
- DataMapper::Constraints::Adapters::SqliteAdapter
- DataMapper::Constraints::Adapters::SqlserverAdapter
- DataMapper::Constraints::Migrations
- DataMapper::Constraints::Migrations::Model
- DataMapper::Constraints::Migrations::Relationship
- DataMapper::Constraints::Migrations::Relationship::ManyToOne
- DataMapper::Constraints::Migrations::SingletonMethods
- DataMapper::Constraints::Relationship
- DataMapper::Constraints::Relationship::ManyToMany
- DataMapper::Constraints::Relationship::OneToMany
- DataMapper::Constraints::Resource

No matching classes.

# dm-constraints

Plugin that adds foreign key constraints to associations. Currently supports only PostgreSQL and MySQL

All constraints are added to the underlying database, but constraining is implemented in pure ruby.

### Constraints

    - :protect     returns false on destroy if there are child records
    - :destroy     deletes children if present
    - :destroy!    deletes children directly without instantiating the resource, bypassing any hooks
                   Does not support 1:1 Relationships as #destroy! is not supported on Resource in dm-master
    - :set_nil     sets parent id to nil in child associations
                   Not valid for M:M relationships as duplicate records could be created (see explanation in specs)
    - :skip        Does nothing with children, results in orphaned records

By default a relationship will PROTECT its children.

### Cardinality Notes

    * 1:1
     * Applicable constraints: [:set_nil, :skip, :protect, :destroy]

    * 1:M
     * Applicable constraints: [:set_nil, :skip, :protect, :destroy, :destroy!]

    * M:M
     * Applicable constraints: [:skip, :protect, :destroy, :destroy!]

### Examples

    # 1:M Example
    class Post
      has n, :comments
      # equivalent to:
      # has n, :comments, :constraint => :protect
    end

    # M:M Example
    class Article
      has n, :tags, :through => Resource, :constraint => :destroy
    end

    class Tags
      has n, :articles, :through => Resource, :constraint => :destroy
    end

    # Intermediary constraints for relationships using :through => Resource
    # are automatically inherited from the M:M relationship.

    # 1:1 Example
    class User
      has 1, :address, :constraint => :protect
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.