public
Description: Fork of DataMapper 0.3 with patches to fix major show-stopping bugs
Homepage:
Clone URL: git://github.com/cardmagic/dm-works.git
Adding :from, :joins, :group and :select (as string) options to finders so that 
there is more backwards compatibility with ActiveRecord
cardmagic (author)
Fri Apr 18 14:35:49 -0700 2008
commit  0692a24228cbc20ac92792400746f064ac4dfcbc
tree    efa0df3029b038052458f6581444741babb32db6
parent  b4a0630cb95199a8753ed0d2aad917c51926feac
...
42
43
44
45
 
46
47
48
...
42
43
44
 
45
46
47
48
0
@@ -42,7 +42,7 @@ module DataMapper
0
       $LOAD_PATH << (DM_PLUGINS_ROOT + '/dataobjects')
0
 
0
       FIND_OPTIONS = [
0
-        :select, :offset, :limit, :class, :include, :shallow_include, :reload, :conditions, :order, :intercept_load
0
+        :select, :offset, :limit, :class, :include, :shallow_include, :reload, :conditions, :order, :intercept_load, :from, :joins, :group
0
       ]
0
 
0
       TABLE_QUOTING_CHARACTER = '`'.freeze
...
126
127
128
129
 
130
131
132
...
146
147
148
 
 
 
149
150
 
151
152
153
...
161
162
163
 
 
 
164
165
166
...
261
262
263
264
265
 
 
 
 
 
 
 
 
 
 
 
 
 
266
267
268
...
271
272
273
 
 
 
 
274
275
276
...
296
297
298
 
 
 
 
299
300
301
...
421
422
423
 
 
424
425
426
...
126
127
128
 
129
130
131
132
...
146
147
148
149
150
151
152
153
154
155
156
157
...
165
166
167
168
169
170
171
172
173
...
268
269
270
 
 
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
...
289
290
291
292
293
294
295
296
297
298
...
318
319
320
321
322
323
324
325
326
327
...
447
448
449
450
451
452
453
454
0
@@ -126,7 +126,7 @@ module DataMapper
0
 
0
           end
0
           
0
-          attr_reader :conditions, :database_context, :options
0
+          attr_reader :conditions, :database_context, :options, :select, :from, :joins
0
           
0
           def initialize(adapter, database_context, primary_class, options = {})
0
             @adapter, @database_context, @primary_class = adapter, database_context, primary_class
0
@@ -146,8 +146,12 @@ module DataMapper
0
             end
0
             # END
0
             
0
+            @select = @options[:select] if @options[:select].is_a?(String)
0
+            @from = @options[:from]
0
+            @group = @options[:group]
0
             @order = @options[:order]
0
             @limit = @options[:limit]
0
+            @joins = @options[:joins]
0
             @offset = @options[:offset]
0
             @reload = @options[:reload]
0
             @instance_id = conditions_hash[:id]
0
@@ -161,6 +165,9 @@ module DataMapper
0
               #<#{self.class.name}:0x%x
0
                 @database=#{@adapter.name}
0
                 @reload=#{@reload.inspect}
0
+                @from=#{@from.inspect}
0
+                @select=#{@select.inspect}
0
+                @joins=#{@joins.inspect}
0
                 @order=#{@order.inspect}
0
                 @limit=#{@limit.inspect}
0
                 @offset=#{@offset.inspect}
0
@@ -261,8 +268,19 @@ module DataMapper
0
           def to_parameterized_sql
0
             parameters = []
0
             
0
-            sql = 'SELECT ' << columns_for_select.join(', ')
0
-            sql << ' FROM ' << from_table_name            
0
+            cfs = columns_for_select
0
+
0
+            if @select.nil?
0
+              sql = 'SELECT ' << cfs.join(', ')
0
+            else
0
+              sql = 'SELECT ' << @select.to_s
0
+            end
0
+
0
+            if @from.nil?
0
+              sql << ' FROM ' << from_table_name
0
+            else
0
+              sql << ' FROM ' << @from.to_s
0
+            end
0
             
0
             included_associations.each do |association|
0
               sql << ' ' << association.to_sql
0
@@ -271,6 +289,10 @@ module DataMapper
0
             shallow_included_associations.each do |association|
0
               sql << ' ' << association.to_shallow_sql
0
             end
0
+
0
+            unless @joins.nil?
0
+              sql << @joins.to_s
0
+            end
0
             
0
             unless conditions_empty?
0
               sql << ' WHERE ('
0
@@ -296,6 +318,10 @@ module DataMapper
0
               end
0
             end # unless conditions_empty?
0
             
0
+            unless @group.nil?
0
+              sql << 'GROUP BY ' << @group.to_s
0
+            end
0
+            
0
             unless @order.nil?
0
               sql << ' ORDER BY ' << @order.to_s
0
             end
0
@@ -421,6 +447,8 @@ module DataMapper
0
                   case x = @options[:select]
0
                   when Array then x
0
                   when Symbol then [x]
0
+                  when String
0
+                    primary_class_table.columns.reject { |column| column.lazy? }
0
                   else raise ':select option must be a Symbol, or an Array of Symbols'
0
                   end.map { |name| primary_class_table[name] }
0
                 else

Comments