public
Fork of sam/dm-core
Description: DataMapper - Core
Homepage: http://datamapper.org
Clone URL: git://github.com/somebee/dm-core.git
Search Repo:
fixed associations to send options through to query
somebee (author)
Wed May 14 18:08:25 -0700 2008
commit  1c7c5ba4893a9d19b3b84e95bb3f6f92de00f802
tree    d086b2ddb75adad02f00ffb91eb61cc4941a8029
parent  6160981583de998b75d7ae925c1864c77370e176
...
9
10
11
12
13
14
15
16
17
18
...
9
10
11
 
 
 
 
12
13
14
0
@@ -9,10 +9,6 @@
0
         raise ArgumentError, "+name+ should be a Symbol, but was #{name.class}", caller unless Symbol === name
0
         raise ArgumentError, "+options+ should be a Hash, but was #{options.class}", caller unless Hash === options
0
 
0
- if (unknown_options = options.keys - OPTIONS).any?
0
- raise ArgumentError, "+options+ contained unknown keys: #{unknown_options * ', '}"
0
- end
0
-
0
         child_model_name = DataMapper::Inflection.demodulize(self.name)
0
         parent_model_name = options.fetch(:class_name, DataMapper::Inflection.classify(name))
0
 
...
9
10
11
12
13
14
15
16
17
18
...
9
10
11
 
 
 
 
12
13
14
0
@@ -9,10 +9,6 @@
0
         raise ArgumentError, "+name+ should be a Symbol, but was #{name.class}", caller unless Symbol === name
0
         raise ArgumentError, "+options+ should be a Hash, but was #{options.class}", caller unless Hash === options
0
 
0
- if (unknown_options = options.keys - OPTIONS).any?
0
- raise ArgumentError, "+options+ contained unknown keys: #{unknown_options * ', '}"
0
- end
0
-
0
         child_model_name = DataMapper::Inflection.demodulize(self.name)
0
         parent_model_name = options[:class_name] || DataMapper::Inflection.classify(name)
0
 
...
3
4
5
6
 
7
8
9
10
11
12
13
14
15
16
17
18
19
...
3
4
5
 
6
7
8
9
10
11
12
 
 
 
 
13
14
15
0
@@ -3,17 +3,13 @@
0
 module DataMapper
0
   module Associations
0
     module OneToMany
0
- OPTIONS = [ :class_name, :child_key, :parent_key, :min, :max, :order ]
0
+ OPTIONS = [ :class_name, :child_key, :parent_key, :min, :max ]
0
 
0
       private
0
 
0
       def one_to_many(name, options = {})
0
         raise ArgumentError, "+name+ should be a Symbol (or Hash for +through+ support), but was #{name.class}", caller unless Symbol === name || Hash === name
0
         raise ArgumentError, "+options+ should be a Hash, but was #{options.class}", caller unless Hash === options
0
-
0
- if (unknown_options = options.keys - OPTIONS).any?
0
- raise ArgumentError, "+options+ contained unknown keys: #{unknown_options * ', '}"
0
- end
0
 
0
         child_model_name = options.fetch(:class_name, DataMapper::Inflection.classify(name))
0
 
...
9
10
11
12
13
14
15
16
17
18
...
9
10
11
 
 
 
 
12
13
14
0
@@ -9,10 +9,6 @@
0
         raise ArgumentError, "+name+ should be a Symbol, but was #{name.class}", caller unless Symbol === name
0
         raise ArgumentError, "+options+ should be a Hash, but was #{options.class}", caller unless Hash === options
0
 
0
- if (unknown_options = options.keys - OPTIONS).any?
0
- raise ArgumentError, "+options+ contained unknown keys: #{unknown_options * ', '}"
0
- end
0
-
0
         child_model_name = options.fetch(:class_name, DataMapper::Inflection.classify(name))
0
         parent_model_name = DataMapper::Inflection.demodulize(self.name)
0
 
...
36
37
38
39
40
41
42
 
43
44
45
...
47
48
49
50
 
51
52
53
54
...
83
84
85
86
87
88
 
89
90
91
92
93
94
 
95
96
97
...
36
37
38
 
39
40
 
41
42
43
44
...
46
47
48
 
49
50
51
52
53
...
82
83
84
 
 
 
85
86
87
88
89
90
 
91
92
93
94
0
@@ -36,10 +36,9 @@
0
 
0
       def get_children(parent)
0
         query = child_key.to_query(parent_key.get(parent))
0
- query.merge!({:order => @child_order}) if @child_order
0
         
0
         DataMapper.repository(parent.repository.name) do
0
- child_model.all(query)
0
+ child_model.all(query.merge(@query))
0
         end
0
       end
0
 
0
@@ -47,7 +46,7 @@
0
         query = parent_key.to_query(child_key.get(child))
0
 
0
         DataMapper.repository(repository_name) do
0
- parent_model.first(query)
0
+ parent_model.first(query.merge(@query))
0
         end
0
       end
0
 
0
0
@@ -83,15 +82,13 @@
0
           raise ArgumentError, "+parent_properties+ must be an Array or nil, but was #{parent_properties.class}", caller unless Array === parent_properties
0
         end
0
         
0
- if child_order = options[:order]
0
- raise ArgumentError, "+child_order+ must be an Array or nil, but was #{child_order.class}", caller unless Array === child_order
0
- end
0
+ query = options.reject{ |key,val| [:class_name, :child_key, :parent_key, :min, :max].include?(key) }
0
 
0
         @name = name
0
         @repository_name = repository_name
0
         @child_model_name = child_model_name
0
         @child_properties = child_properties # may be nil
0
- @child_order = child_order # may be nil
0
+ @query = query
0
         @parent_model_name = parent_model_name
0
         @parent_properties = parent_properties # may be nil
0
         @loader = loader

Comments

    No one has commented yet.