Now, thank you for the quick reply.
I might not be understanding what you need here, but assuming you want
your API to look like this:
product.sales('2010-08-20')
>>> [<Sale>,<Sale>, ...]
Right, that is the idea.
First of all, is that enough? If you just want to dynamically access
an extra-filtered list of Sale objects then you could easily do that
with either a function or a method on Product, etc. I.e. it doesn't
have to be provided by the ORM necessarily.
True, but I feel I am losing functionality associated with the orm to be
able to reference that like the rest of the relation properties. Maybe
a larger reason for this is depending on the data, it may be very
inefficient to bring back all the rows and filter them in python when
the database could have easily done so for you. Still, I appreciate the
idea, and I'll kick it around a bit...
Or do you really need for this to be an ORM (relationship) property?
If so then I probably am not the one with your answer because I've not
done much of that, but perhaps you could use the lazy='dynamic'
parameter to relationship() ?
Hmm... it looks like maybe this is the type of situation lazy='dynamic'
is meant for. Thanks for pointing me that way.
On Fri, 2010-08-20 at 11:58 -0700, Kent wrote:
I've run into this a variant of this same problem several times now,
so I want to ask if you know of a good way to solve the problem.
Some relation()s are based on extra criteria (besides primary key
joins), but otherwise would be nice to work just like normal relation
properties.
A simplified example:
Say you have two entities: *Product and Sale*:
Product (productid, regularprice, description)
and
Sale (productid, startingdate, endingdate, saleprice)
I would like to be able to add a relationship() to the Product mapper
for a 'sales' collection, but be able to *pass in the date*, so that I
can populate a Product instance's 'sales' property, like prod.sales,
as a [list of Sale objects joined by primary key with filter of passed
date].
I believe I can get there with contains_eager(), but then the problem
is I need to redefine this query over each place I use it, instead of
being able to tell the *mapper* about it and treat it like a normal
relationship.
Is there an elegant way to accomplish this type of "conditional" join/
relation?
Thanks in advance,
Kent
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.