3 messages in com.googlegroups.sqlalchemy[sqlalchemy] Re: SQLAlchemy denormali...
FromSent OnAttachments
PaStIcHiO29 Nov 2007 05:10 
Michael Bayer29 Nov 2007 07:43 
Rick Morrison29 Nov 2007 08:00 
Subject:[sqlalchemy] Re: SQLAlchemy denormalization.
From:Rick Morrison (rick@gmail.com)
Date:11/29/2007 08:00:48 AM
List:com.googlegroups.sqlalchemy

Another technique to think about would be to enumerate the child addresses with a small integer value, say "sequence". You can then add the "order_by" to the relation to fetch the addresses in sequence order, and by convention the first address in the result list -- the one with min(sequence) in the group -- is the default address. If you then use 'dynamic' on the relation, you can fetch only the first (and default) address by using .first() on the resulting Query object, or .all() to get all the addresses. A small side benefit is that if the default address is then deleted, the next in line will become the new default.

Of course the price of this behavior is to maintain the sequences, but that's pretty straightforward.