<div class="gmail_quote">Thanks James,<div><br></div><div>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.</div>
<div><br></div><div>It seems to be a pretty typical feature in other ORMs (mainly php) that I have used.</div><div><br></div><div>I will continue to investigate.</div><div><br></div><div>Cheers,</div><div>Pete<br><br><div class="gmail_quote">
2009/9/18 James Henstridge <span dir="ltr"><<a href="mailto:james@jamesh.id.au" target="_blank">james@jamesh.id.au</a>></span><div><div></div><div class="h5"><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div></div><div>On Wed, Sep 16, 2009 at 9:00 PM, peter websdell<br>
<<a href="mailto:flyingdeckchair@googlemail.com" target="_blank">flyingdeckchair@googlemail.com</a>> wrote:<br>
> Hello all,<br>
> I'm new to Storm and this list.<br>
> I have assumed so far that storm uses lazy-loading to get attributes from<br>
> relations. Is it possible to specify auto loading of related tables? If so,<br>
> can it be done on-the-fly, rather then in the class definition?<br>
<br>
</div></div>When you access a "Reference" attribute on an object, Storm will<br>
perform a store.get() call to retrieve the related object. If the<br>
object has already been loaded, then it will be returned directly. If<br>
it hasn't, this will result in a query.<br>
<br>
If you want to retrieve pairs of objects in a single query, you can do<br>
that with store.find(). Something like this:<br>
<br>
class A(object):<br>
__storm_table__ = "a"<br>
id = Int(primary=True)<br>
<br>
class B(object):<br>
__storm_table__ = "b"<br>
id = Int(primary=True)<br>
a_id = Int()<br>
a = Reference(a_id, A.id)<br>
<br>
result = store.find((B, A), B.a_id == A.id)<br>
for (b, a) in result:<br>
# The following won't issue a query, because "a" was loaded at the<br>
same time as "b".<br>
assert b.a == a<br>
<br>
Hope this helps,<br>
<font color="#888888"><br>
James.<br>
</font></blockquote></div></div></div><br></div>
</div><br>