
Collection#concat doesn't update query for lazy_loading
Reported by Robert Sköld | August 24th, 2009 @ 12:55 PM
Example program which illustrates the issue (tested with ruby 1.8.6 (2008-08-11) [universal-darwin9.0]):
require "rubygems"
require "dm-core"
require "dm-serializer"
class Item
include DataMapper::Resource
property :id, Serial
property :title, String
property :kind, Integer
property :content, Text
end
DataMapper::Logger.new(STDOUT, :debug)
DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/test.db")
DataMapper.auto_migrate!
0.upto(100) do |i|
item = Item.create( :title => "item#{i}" , :content => "bla blab la " , :kind => ( rand() > 0.5 ? 1 : 2 ) )
end
as = Item.all( :kind => 1 )
bs = Item.all( :kind => 2 )
merged = as.concat( bs )
puts "Merged: #{merged.size}" # => 101
puts "Without json: #{merged.map { |item| item }.size}" # => 101
puts "With json: #{merged.map { |item| item.to_json }.size} (should be 101)" # => ~50
Edit: Updated example, it has the same error without the "has n" so now it's more compact and to the point.
Comments and changes to this ticket
-
Martin Gamsjaeger (snusnu) August 24th, 2009 @ 12:58 PM
- State changed from new to confirmed
-
Robert Sköld August 24th, 2009 @ 01:34 PM
I'm not entirely sure, but it seems this is fixed in the current next branch?
-
Jonathan Stott (namelessjon) October 9th, 2009 @ 09:11 AM
- Tag changed from collection, concat, to_json to collection, concat, lazy_loading, one_file_test, sel
Okay, this isn't a to_json problem at all. It's actually a problem with lazy loading in merged collections. Find attached the script which shows this. The issue seems to be that concat isn't updating the query associated with the merged collection.
-
Jonathan Stott (namelessjon) October 9th, 2009 @ 09:18 AM
Ooops, uploading the correct version of the ticket script
-
Jonathan Stott (namelessjon) October 11th, 2009 @ 05:14 AM
- Title changed from Collection#concat doesn't work with to_json to Collection#concat doesn't update query for lazy_loading
Just changing the title to one which is more accurate
-
Dan Kubb (dkubb) November 6th, 2009 @ 02:01 AM
Would it be correct to have Collection#concat use the same logic that Collection#union does to combine the Query objects, only instead of returning a new Collection (as #union does), it would just overwrite the current Collection's Query object in @query?
If so, a patch with failing specs would be gladly accepted. The changes to Collection#concat would use some of the same behavior in Collection#set_operation to figure out what the combined Query object should be, only setting @query directly.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »