public
Rubygem
Description: DataMapper - Core
Homepage: http://datamapper.org
Clone URL: git://github.com/sam/dm-core.git
Fix for cross repository query bug in DOA
guyvdb (author)
Tue Apr 22 21:24:35 -0700 2008
commit  a90ceab95f70e08a5ed16c9795b4a8adf3735c60
tree    53e53f79f643dd9b466e6217bbcb28c56ab8cfea
parent  92470da3a1b03d83a4bb33c3e0bb3ea9e7f7baab
...
370
371
372
 
 
373
374
375
376
377
378
379
380
381
382
 
 
 
 
 
 
 
 
 
383
384
385
...
416
417
418
419
420
421
 
 
 
 
 
 
 
 
422
423
424
...
370
371
372
373
374
375
376
377
378
379
380
 
 
 
 
381
382
383
384
385
386
387
388
389
390
391
392
...
423
424
425
 
 
 
426
427
428
429
430
431
432
433
434
435
436
0
@@ -370,16 +370,23 @@ module DataMapper
0
             WHERE #{model.key(name).map { |key| "#{quote_column_name(key.field)} = ?" }.join(' AND ')}
0
           EOS
0
         end
0
+
0
+
0
 
0
         def query_read_statement(query)
0
           qualify = query.links.any?
0
 
0
           sql = "SELECT "
0
 
0
- sql << query.fields.map do |property|
0
- # deriving the model name from the property and not the query
0
- # allows for "foreign" properties to be qualified correctly
0
- model_name = property.model.storage_name(property.model.repository.name)
0
+ sql << query.fields.map do |property|
0
+ # TODO Should we raise an error if there is no such property in the
0
+ # repository of the query?
0
+ #
0
+ #if property.model.properties(query.repository.name)[property.name].nil?
0
+ # raise "Property #{property.model.to_s}.#{property.name.to_s} not available in repository #{query.repository.name}."
0
+ #end
0
+ #
0
+ model_name = property.model.storage_name(query.repository.name)
0
             property_to_column_name(model_name, property, qualify)
0
           end.join(', ')
0
 
0
@@ -416,9 +423,14 @@ module DataMapper
0
           unless query.conditions.empty?
0
             sql << " WHERE "
0
             sql << "(" << query.conditions.map do |operator, property, value|
0
- # deriving the model name from the property and not the query
0
- # allows for "foreign" properties to be qualified correctly
0
- model_name = property.model.storage_name(property.model.repository.name)
0
+ # TODO Should we raise an error if there is no such property in the
0
+ # repository of the query?
0
+ #
0
+ #if property.model.properties(query.repository.name)[property.name].nil?
0
+ # raise "Property #{property.model.to_s}.#{property.name.to_s} not available in repository #{query.repository.name}."
0
+ #end
0
+ #
0
+ model_name = property.model.storage_name(query.repository.name)
0
               case operator
0
                 when :eql, :in then equality_operator(query,model_name,operator, property, qualify, value)
0
                 when :not then inequality_operator(query,model_name,operator, property, qualify, value)
...
7
8
9
 
10
11
12
...
187
188
189
 
 
 
 
 
190
191
192
...
206
207
208
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
209
210
211
...
7
8
9
10
11
12
13
...
188
189
190
191
192
193
194
195
196
197
198
...
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
0
@@ -7,6 +7,7 @@ begin
0
   require 'do_sqlite3'
0
 
0
   DataMapper.setup(:sqlite3, "sqlite3://#{INTEGRATION_DB_PATH}")
0
+ DataMapper.setup(:mock, "mock:///mock.db")
0
 
0
   describe DataMapper::Query do
0
     describe 'when ordering' do
0
@@ -187,6 +188,11 @@ begin
0
           property :region_id, Fixnum
0
           property :name, String
0
 
0
+ repository(:mock) do
0
+ property :land, String
0
+ end
0
+
0
+
0
           many_to_one :region
0
         end
0
 
0
@@ -206,6 +212,28 @@ begin
0
         end
0
       end
0
 
0
+ it 'should require that all properties in :fields and all :links come from the same repository'
0
+# do
0
+# land = Factory.properties(:mock)[:land]
0
+# fields = []
0
+# Vehicle.properties(:sqlite3).map do |property|
0
+# fields << property
0
+# end
0
+# fields << land
0
+#
0
+# lambda{
0
+# begin
0
+# repository(:sqlite3) do
0
+# query = DataMapper::Query.new(Vehicle,:links => [:factory], :fields => fields)
0
+# results = @adapter.read_set(repository(:sqlite3), query)
0
+# end
0
+# rescue RuntimeError
0
+# $!.message.should == 'Property Factory.land not available in repository sqlite3.'
0
+# raise $!
0
+# end
0
+# }.should raise_error(RuntimeError)
0
+# end
0
+
0
       it 'should accept a DM::Assoc::Relationship as a link' do
0
         factory = DataMapper::Associations::Relationship.new(
0
           :factory,

Comments

    No one has commented yet.