Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added in some basic documentation for has()

  • Loading branch information...
commit 6340ca2ca2514eccd35043328b5db3873795d579 1 parent 6452108
@andykent andykent authored Dan Kubb committed
Showing with 26 additions and 1 deletion.
  1. +26 −1 lib/data_mapper/associations.rb
View
27 lib/data_mapper/associations.rb
@@ -19,7 +19,27 @@ def relationships
def n
1.0/0
end
-
+
+ #
+ # A shorthand, clear syntax for defining resource relationships.
+ #
+ # Basic Usage Examples...
+ #
+ # * has 1..n, :friends # one_to_many :friends
+ # * has 1, :friend # one_to_one, :friend
+ # * has n..1, :friends # many_to_one, :friends
+ # * has n..n, :friends # many_to_many, :friends
+ #
+ # Advanced Usage Examples...
+ #
+ # * has 1..3, :friends # one_to_many :friends, :min => 3, :max => 3
+ # * has 1..2, :friends, :max=>5 # one_to_many :friends, :min => 2, :max => 5
+ # * has 3, :friends # one_to_many :friends, :min => 3, :max => 3
+ # * has 3..3, :friends # many_to_many :friends, :left=>{:min=>3, :max=>3}, :right=>{:min=>3, :max=>3}
+ # * has 1, :friend, :class_name=>'User' # one_to_one :friend, :class_name => 'User'
+ #
+ # * <tt>contraints</tt> - constraints can be defined as either a fixed number, Infinity or a range
+ #
def has(cardinality, name, options = {})
case cardinality
when Range
@@ -39,7 +59,12 @@ def has(cardinality, name, options = {})
end || raise(ArgumentError, "Cardinality #{cardinality.inspect} (#{cardinality.class}) not handled")
end
+
private
+
+ # A support method form converting numbers ranges or Infinity values into a {:min=>x, :max=>y} hash.
+ #
+ # * <tt>contraints</tt> - constraints can be defined as either a fixed number, Infinity or a range
def extract_min_max(contraints)
case contraints
when Range
Please sign in to comment.
Something went wrong with that request. Please try again.