On Aug 22, 2011, at 12:15 PM, Matthias wrote:

> Hello,
> 
> I am (ab)using sqlalchemy for versioning all my content. It allows me
> to do things like
> 
> session.query(Parent).options(VersionOption(target_version =
> 123)).filter(Parent.children.any(Child.name == 'c1')).all()
> 
> and the result will reflect exactly the state at version 123.
> 
> The querying part already works, at its heart the relationship between
> Parent and Child (one-to-many) looks like
> 
> secondary = j
> primaryjoin = Child.parent_id == j.c.content_id
> secondaryjoin = j.c.content_id_at_version == Parent.id
> 
> where j is an aliased select and join between several other tables to
> generate the "translation table" between arbitrary_content_id and the
> latest content which belongs to the same object.
> 
> Now I'd also love to be able to do
> 
> alice.children.append(Child(name = 'bob'))
> 
> This currently gives me a
> 
> Module sqlalchemy.orm.dependency:1124 in _run_crud
>>> statement = self.secondary.insert()
> AttributeError: 'Alias' object has no attribute 'insert'

add viewonly=True to the relationship.  This relationship can't be writable 
since you're establishing secondary against a join of two tables, so that's not 
supported on the write side for many-to-many.

There's of course ways to write to that join if you mapped an association class 
to it, using two distinct relationships instead of a single one that uses 
"secondary".   The association can be made to act like m2m on the object 
manipulation side using the association proxy.   The association proxy can make 
any attribute look like anything, pretty much.

http://www.sqlalchemy.org/docs/orm/relationships.html#association-object
http://www.sqlalchemy.org/docs/orm/extensions/associationproxy.html

-- 
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