Looks like this almost-sorta works:
class TagMixin(object):
@declared_attr
def TagClass(cls):
class Tag(BaseModel):
__tablename__ = "tag_%s" % cls.__tablename__
id = Column(types.Integer, primary_key=True)
time_created = Column(types.DateTime, default=datetime.now,
nullable=False)
row_id = Column(types.Integer, ForeignKey(cls.id), index=True)
name = Column(types.String, nullable=False, index=True)
# This part breaks with... sqlalchemy.exc.InvalidRequestError: Table
'tag_user' is already defined for this MetaData instance.
# @declared_attr
# def tags(cls):
# return orm.relationship(cls.TagClass, backref='tagged')
class User(BaseModel, TagMixin):
__tablename__ = 'user'
id = Column(types.Integer, primary_key=True)
...
The appropriate tables do get generated on create_all(). But as soon as I
touch the User.TagClass attribute, it barfs with the same error again:
InvalidRequestError: Table 'tag_user' is already defined for this MetaData
instance. Specify 'extend_existing=True' to redefine options and columns on
an existing Table object.
--
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.