lazy load property grouping not working for me

10 views
Skip to first unread message

daniel_spaniel

unread,
Feb 11, 2010, 7:00:23 PM2/11/10
to DataMapper
Hi
I am following the documentation about lazy loading properties. I
especially liked the concept of grouping the lazy loading properties
together. So I tried it. But when I look at the sql it does not really
happen as expected.

DataMapper.setup(:default, 'sqlite3://:memory:')

class Post
include DataMapper::Resource

property :id, Serial
property :name, String, :lazy => [:show]
property :volume, Integer, :lazy => [:show]
property :idea, String, :lazy => [:report]

end

Post.auto_migrate!
Post.create(:name=>'Dan',:volume=>5,:idea=>'moo')

Post.first.name

When I look at query for ( Post.first.name ) I see only the name
property loaded, not the name and volume together which I thought was
supposed to happen since they are in the same lazy :show group.
Am I doing something wrong?

~ Dan

casual

unread,
Feb 12, 2010, 7:37:52 PM2/12/10
to DataMapper
I believe this is a bug, I just wrote a test for it in the current dm-
core and it fails:

--------------------------------
# in resource_shared_spec/ describe 'lazy loading'

describe "with context" do
before(:all) do
rescue_if @skip do
comment = @comment_model.create(:body => 'I really like your
Def Jux baby tee.', :url => 'http://blog.foo.com', :gravatar_url =>
'http://gravatar.com/image.png', :user => @user)

@comment = @comment_model.get(*comment.key)
end
end

it "should not fetch the lazy keys" do
@comment_model.properties[:url].loaded?(@comment).should_not
be(true)
@comment_model.properties[:gravatar_url].loaded?
(@comment).should_not be(true)
end

it "should fetch all lazy kys in the context" do
@comment.url
@comment_model.properties[:url].loaded?(@comment).should
be(true)
@comment_model.properties[:gravatar_url].loaded?
(@comment).should be(true) # => fails a returning false
end
end
-----------------------------

I will take a look at the lighthouse project and see if there is a
ticket for this already, if not I'll file one.

casual

unread,
Feb 12, 2010, 9:49:16 PM2/12/10
to DataMapper
Ok, I committed a fix (yet to be approved) to the current development:
http://datamapper.lighthouseapp.com/projects/20609-datamapper/tickets/1197-lazy-contexts-gone-again#ticket-1197-2


And to help you in the meantime, I applied that fix as a patch to
0.10.2: http://github.com/kabari/dm-core/tree/10_2_patch, just clone
it and sudo rake install, that should help you out until the next
release :)

daniel_spaniel

unread,
Feb 14, 2010, 1:16:05 PM2/14/10
to DataMapper
Thanks for the fix C..
I hope some day I can contribute a fix or two myself.
~ D

On Feb 12, 6:49 pm, casual <kab...@gmail.com> wrote:
> Ok, I committed a fix (yet to be approved) to the current development:http://datamapper.lighthouseapp.com/projects/20609-datamapper/tickets...

Reply all
Reply to author
Forward
0 new messages