Hello,
I'm trying to do the following:
'home': orm.composite(
Address,
user.c.HomeAddress_Street,
# The following column is a UUID but is a foreign key to a
mapped
# table in SQLAlchemy, ideally would be to say
relationship(City)
# and specify the column
user.c.HomeAddress_City,
user.c.HomeAddress_ZipCode
)
I've read in this newsgroups that in the past somebody tried to do the
samething, and he was referred to establish a listener to the set
event. I already tried that by defining an AttributeExtension class
and checking that if is an UUID a query must be done to get the mapped
object. However I noticed that when a SQLAlchemy session does a
commit() it tries to initialize the same object in
sqlalchemy.orm.strategies:CompositeColumnLoader inside the copy
function of the init_class_attribute method, without calling my event
listener.
As such I tried a simple if isinstance(city, uuid.UUID): city =
City.load(city), where this method is just:
@classmethod
def load(cls, id):
session = Session()
obj = session.query(cls).get(id)
session.close()
return obj
However during session.commit() it appears that my Session class (made
with scoped_session(sessionmaker()) ) goes to None (and crashes).
Is this an expected behavior?
Is there any simpler way to have a mapped class in a composite column
with a foreign key?
Thanks
--
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.