I'm working on a database where the relation between users and objects
is defined by an association table that looks like:
role_objects_table = Table("role_objects", metadata,
Column("objects_id", Integer,
ForeignKey("objects.objects_id"),
primary_key=True),
Column("role",Role_Type),
Column("user_id", Integer,
ForeignKey("tg_user.user_id"),
primary_key=True))
Where Role_Type is an Enum class that translates roles onto Unicode(1).
And Objects is mapped like so:
assign_mapper(session.context, Objects, objects_table, properties = dict(
#...
responsibles = relation(User, secondary=role_objects_table,
primaryjoin = and_(objects_table.c.objects_id ==
role_objects_table.c.objects_id,
role_objects_table.c.role == 'R')),
approvers = relation(User, secondary=role_objects_table,
primaryjoin = and_(objects_table.c.objects_id ==
role_objects_table.c.objects_id,
role_objects_table.c.role == 'A')),
#...
)
So basically the relationship between users and objects is typed by
the role field. This is a textbook use case for the use of an
association object, but using an association object is really
annoying. I would really like to be able to treat each relation as a
normal many to many relation and not have to create intermediate
objects just to set one field to a constant value.
In looking through the archives I found:
> You could go more nuts with [object properties] by having the list be a
> subclass of "list" which properly does mutation operations too, creates
> the association objects automatically, etc.
Which seems to be what I'm looking to do. I'm assuming that the "list"
referenced here is custom collection_class, but I don't see any
obvious hooks into the secondary table and trying to manage the state
of intermediate objects is more work than I'd like.
In looking through the code, I noticed
sqlalchemy.orm.attributes.AttributeExtension, which makes it pretty
easy to hook into the event I'm interested in, but I'm having trouble
finding a reference to the secondary table.
Any guidance would be appreciated.
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users