[storm] Fwd: Lazy loading?

peter websdell flyingdeckchair at googlemail.com
Fri Sep 18 09:00:46 BST 2009


Thanks James,
I'm surprised there isn't a trick - perhaps something that can be added in
the class definition - where I can force the object to load with the
reference, for situations where I'll be loading large numbers of rows, all
of which will require access to the related table. I'd seen the option to
load multiple objects in the tutorial, but it's a bit messy compared to
simply accessing the Reference of an object.

It seems to be a pretty typical feature in other ORMs (mainly php) that I
have used.

I will continue to investigate.

Cheers,
Pete

2009/9/18 James Henstridge <james at jamesh.id.au>

On Wed, Sep 16, 2009 at 9:00 PM, peter websdell
> <flyingdeckchair at googlemail.com> wrote:
> > Hello all,
> > I'm new to Storm and this list.
> > I have assumed so far that storm uses lazy-loading to get attributes from
> > relations. Is it possible to specify auto loading of related tables? If
> so,
> > can it be done on-the-fly, rather then in the class definition?
>
> When you access a "Reference" attribute on an object, Storm will
> perform a store.get() call to retrieve the related object.  If the
> object has already been loaded, then it will be returned directly.  If
> it hasn't, this will result in a query.
>
> If you want to retrieve pairs of objects in a single query, you can do
> that with store.find().  Something like this:
>
> class A(object):
>    __storm_table__ = "a"
>    id = Int(primary=True)
>
> class B(object):
>    __storm_table__ = "b"
>    id = Int(primary=True)
>    a_id = Int()
>    a = Reference(a_id, A.id)
>
> result = store.find((B, A), B.a_id == A.id)
> for (b, a) in result:
>    # The following won't issue a query, because "a" was loaded at the
> same time as "b".
>    assert b.a == a
>
> Hope this helps,
>
> James.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://lists.ubuntu.com/archives/storm/attachments/20090918/48ed224e/attachment-0002.htm 


More information about the storm mailing list