Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Commit

Permalink
[dm-constraints] Automatically add constraints to all models when req…
Browse files Browse the repository at this point in the history
…uired

* This change is consistent with behavior of other DM plugins.
* Minor doc update to show that intermediaries inherit constraints from
  the anonymous m:m relationships.

[#1078 state:resolved]
  • Loading branch information
dkubb committed Nov 10, 2009
1 parent c0e0b46 commit 21ffecf
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 4 additions & 0 deletions dm-constraints/README.rdoc
Expand Up @@ -42,10 +42,14 @@ end
class Articles
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 Farmer
has 1, :beloved_sheep, :constraint => :protect
Expand Down
2 changes: 2 additions & 0 deletions dm-constraints/lib/dm-constraints.rb
Expand Up @@ -57,6 +57,8 @@ def self.included(model)
end
RUBY
end

Model.append_inclusions self
end

module Migrations
Expand Down
4 changes: 0 additions & 4 deletions dm-constraints/spec/integration/constraints_spec.rb
Expand Up @@ -8,7 +8,6 @@

class ::Article
include DataMapper::Resource
include DataMapper::Constraints

property :id, Serial
property :title, String, :nullable => false
Expand All @@ -21,7 +20,6 @@ class ::Article

class ::Author
include DataMapper::Resource
include DataMapper::Constraints

property :first_name, String, :key => true
property :last_name, String, :key => true
Expand All @@ -32,7 +30,6 @@ class ::Author

class ::Comment
include DataMapper::Resource
include DataMapper::Constraints

property :id, Serial
property :body, Text
Expand All @@ -45,7 +42,6 @@ class ::Comment
# on the other end
class ::Revision
include DataMapper::Resource
include DataMapper::Constraints

property :id, Serial
property :text, String
Expand Down

0 comments on commit 21ffecf

Please sign in to comment.