<div dir="ltr">Hi Dylan,<br><br>I think this is the most efficient way:<br><br><br><div style="font-family:arial,sans-serif;font-size:13px">class Person(db.Entity):<br> id = PrimaryKey(int, auto=True)</div><div style="font-family:arial,sans-serif;font-size:13px"> checkouts = Set("Checkout")<br></div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px"> @property</div><div style="font-family:arial,sans-serif;font-size:13px"> def recent_checkouts(self):</div><div style="font-family:arial,sans-serif;font-size:13px"> return Checkout.select(lambda c: c.person == self) \<br> .order_by(lambda c: desc(c.date))[:10]</div><div style="font-family:arial,sans-serif;font-size:13px"> </div><div style="font-family:arial,sans-serif;font-size:13px"><div>class Checkout(db.Entity):<br></div></div><div style="font-family:arial,sans-serif;font-size:13px"> id = PrimaryKey(int, auto=True)</div><div style="font-family:arial,sans-serif;font-size:13px"> person = Required(Person)<br></div><div style="font-family:arial,sans-serif;font-size:13px"> date = Required(date)<br> composite_index(person, date)<br><br><br>Note that I defined composite non-unique index on person and date attributes in Checkout entity. This way DBMS can do filtering and sorting using just one index.<br><br>Regards,<br>Alexander</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Nov 11, 2014 at 3:13 AM, Dylan Staley <span dir="ltr"><<a href="mailto:staley.dylan@gmail.com" target="_blank">staley.dylan@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi all! I'm using these two models:<div><br></div><div><div>class Person(db.Entity):</div><div> id = PrimaryKey(int, auto=True)</div><div> checkouts = Set("Checkout")</div><div><br></div><div> @property</div><div> def recent_checkouts(self):</div><div> # return 10 most recent checkouts</div><div> </div><div><br></div><div>class Checkout(db.Entity):</div><div> id = PrimaryKey(int, auto=True)</div><div> person = Required(Person)</div><div> date = Required(date)</div></div><div><br></div><div>I'd like to be able to call Person.recent_checkouts to get a list of that person's ten most recent checkouts. How would I accomplish this in the most performant manner?</div><div><br></div><div>Best,</div><div>Dylan Staley</div>
<br>_______________________________________________<br>
ponyorm-list mailing list<br>
<a href="mailto:ponyorm-list@ponyorm.org">ponyorm-list@ponyorm.org</a><br>
<a href="/ponyorm-list" target="_blank">/ponyorm-list</a><br>
<br></blockquote></div><br></div>