I want to maintain some groups that change over time.  Specifically, I
have a group table with group names and other attributes.  Every time
an item enters a group, a record is created in an item table with an
entry timestamp (and some other attributes).  Whenever an item leaves
a group, its item table record is updated with an exit timestamp.  I
need to access the group as it was at any specific time.  I cannot
find a nice way with SQLAlchemy ORM to maintain such a Group object
with its Item collection.

The problem seems to be controlling the contents of a collection in an
ORM object.  Using joins I can limit the returned objects to ones that
have certain traits in the associated collection but the collection
itself always has all the collectable objects.

In the orm tutorial, the section "Selecting Entities from Subqueries"
comes close.  That query returns the user (with all its associated
addresses) and a list of the desired addresses.  Is there any way to
get the User object "jack" with only the filtered addresses it the
"addresses" collection of the object?

One way to do this is to set up the relation to filter the objects
(addresses) that appear in the collection (user.addresses).  I do not
want to do this because I want build the query after the mapping is
done (e.g. give me all users that use gmail or something else for
email).

Is this the same question as asked in "filter relation based on column
values" where the recommnendation was to subclass Query?  Similar
threads are "Extended Query subclass with add_named_column method"
and  "Optimizing joined entity loads".

Dynamic Relation Loaders in the SQLAlchemy documentation has an
approach where the collection is returned as a Query object which can
be filtered.  It seems that one can initialize, append to, and remove
from the collection (query) but the interface requires the filter to
be specified and SQL is generated whenever the collection is accessed.

What is the best way to solve this problem?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to