public
Fork of sam/dm-core
Description: DataMapper - Core
Homepage: http://datamapper.org
Clone URL: git://github.com/somebee/dm-core.git
Search Repo:
added finder-functionality to associations
somebee (author)
Thu May 15 03:15:47 -0700 2008
commit  5d0ce7c23948c1ecc71fe3d2639c744b8310fc96
tree    db95b8b38823e9ad64f66402a85bdb3b55253c97
parent  1c7c5ba4893a9d19b3b84e95bb3f6f92de00f802
...
95
96
97
 
 
 
 
 
 
 
 
98
99
100
...
95
96
97
98
99
100
101
102
103
104
105
106
107
108
0
@@ -95,6 +95,14 @@
0
           @dirty_children = []
0
           self
0
         end
0
+
0
+ def all(options={})
0
+ options.empty? ? children : @relationship.get_children(@parent_resource,options,:all)
0
+ end
0
+
0
+ def first(options={})
0
+ options.empty? ? children.first : @relationship.get_children(@parent_resource,options,:first)
0
+ end
0
 
0
         private
0
 
...
34
35
36
37
38
 
 
39
40
41
 
42
43
44
...
34
35
36
 
 
37
38
39
40
 
41
42
43
44
0
@@ -34,11 +34,11 @@
0
         end
0
       end
0
 
0
- def get_children(parent)
0
- query = child_key.to_query(parent_key.get(parent))
0
+ def get_children(parent,options = {},finder = :all)
0
+ query = @query.merge(options).merge(child_key.to_query(parent_key.get(parent)))
0
         
0
         DataMapper.repository(parent.repository.name) do
0
- child_model.all(query.merge(@query))
0
+ finder == :first ? child_model.first(query) : child_model.all(query)
0
         end
0
       end
0
 

Comments

    No one has commented yet.