<div dir="ltr"><div class="gmail_default" style="font-family:trebuchet ms,sans-serif;color:#3d85c6">Change the optional attribute `lazy` to False. So, for example:</div><div class="gmail_default" style="font-family:trebuchet ms,sans-serif;color:#3d85c6"><br></div><div class="gmail_default" style="font-family:trebuchet ms,sans-serif;color:#3d85c6">class File(database.Entity):</div><div class="gmail_default" style="font-family:trebuchet ms,sans-serif;color:#3d85c6">    filename = Required(unicode, lazy=False)</div><div class="gmail_default" style="font-family:trebuchet ms,sans-serif;color:#3d85c6">    ...</div><div class="gmail_default" style="font-family:trebuchet ms,sans-serif;color:#3d85c6"><br></div><div class="gmail_default" style="font-family:trebuchet ms,sans-serif;color:#3d85c6">And then try. Admittedly, I have not tried this out myself, but this should work.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Dec 13, 2014 at 12:50 PM, Tomislav Tustonic <span dir="ltr"><<a href="mailto:ttustonic@outlook.com" target="_blank">ttustonic@outlook.com</a>></span> wrote:<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello<br>
<br>
Is it possible to make an entity always prefetch some related entities?<br>
For example, something like this:<br>
<br>
class Directory(database.Entity):<br>
    path = Required(unicode, unique=True)<br>
    files = Set(lambda: File)<br>
<br>
class File(database.Entity):<br>
    filename = Required(unicode)<br>
    directory = Required(lambda: Directory)<br>
<br>
    @property<br>
    def fullPath(self):<br>
        return os.path.join(self.directory.<u></u>path, self.filename)<br>
<br>
# case 1<br>
with db_session:<br>
    fl = File[1]<br>
print fl.fullPath<br>
<br>
# case 2<br>
with db_session:<br>
    fl = File.select(lambda f: <a href="http://f.id" target="_blank">f.id</a>==1).prefetch(File.<u></u>directory).get()<br>
print fl.fullPath<br>
<br>
Case 1 will not work, case 2 will. So, I'd like to be able to specify that getting File always loads Directory, so that fullPath is available outside db_session. Is it (or will it be) possible?<br>
Somewhat related to this, it would be nice to be able to have 'calculated' attributes, which wouldn't be saved and loaded from the database, but would be serialized using to_dict(). I don't think it's possible now.<br>
<br>
Thanks, Tom<br>
<br>
______________________________<u></u>_________________<br>
ponyorm-list mailing list<br>
<a href="mailto:ponyorm-list@ponyorm.org" target="_blank">ponyorm-list@ponyorm.org</a><br>
<a href="/ponyorm-list" target="_blank">https://mailman-mail5.<u></u>webfaction.com/listinfo/<u></u>ponyorm-list</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><font size="4" face="trebuchet ms, sans-serif" color="#6fa8dc">Kind Regards,</font></div><div><img src="https://brnbcg.blu.livefilestore.com/y1mIyqRuYWMVkEp1XgqnpPJw31rRYoNvXRcLpo1WOUfIx-d9b0krZq2EJ4vUjOgoHcfZow1IZifvV3JxEuWl7yinOPYSMwlrPk7rFfWQ7RMTlkgQ9uTAq0uNQ/Signature1.png?psid=1" width="96" height="69"><br></div><div></div><div><span style="font-family:'trebuchet ms',sans-serif;font-size:large"><font color="#6fa8dc">Quazi Nafiul Islam</font></span></div></div></div>
</div>