Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

DataMapper plugin constraining relationships

Add backports to spec helpers

* Remove explicit requirement of rubygems
latest commit d3aded2d92
Dan Kubb dkubb authored April 08, 2012
Octocat-spinner-32 lib Remove jeweler November 15, 2011
Octocat-spinner-32 spec Add backports to spec helpers April 08, 2012
Octocat-spinner-32 tasks Updated jeweler dep to 1.5.2 February 17, 2011
Octocat-spinner-32 .gitignore Ignore all Gemfile variants apart from the original November 26, 2010
Octocat-spinner-32 Gemfile Remove jeweler November 15, 2011
Octocat-spinner-32 LICENSE Updated Copyright year February 28, 2011
Octocat-spinner-32 README.rdoc Stripped whitespace September 01, 2011
Octocat-spinner-32 Rakefile Remove jeweler November 15, 2011
Octocat-spinner-32 dm-constraints.gemspec Remove jeweler November 15, 2011
README.rdoc

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
Something went wrong with that request. Please try again.