I'm working with a denormalized cache schema, and I've run into a situation
where it would be helpful to be able to create multiple classes that extend
Base but refer to the same __tablename__. Is this possible to do? I am
getting this Exception:
sqlalchemy.exc.InvalidRequestError: Table '[tablename]' is already
defined for this MetaData instance. Specify 'extend_existing=True' to
redefine options and columns on an existing Table object.
For a little more insight, we have some attributes that always have exactly
one value (user who created the issue), and other attributes that can have
1 or more values (user-defined tags for the issue). If we were being
exhaustive, we would create two "cached" tables for our issues since
sometimes we want to display recent issues sometimes by user and sometimes
by tag:
* issue_user
* issue_tag
However, we can get away with writing just one table and querying it with
an appropriate group_by("user_id") to achieve the same end as having 2
tables. Since my application should behave as if there were 2 separate
cache tables (and I'd like to keep open the option of adding two separate
cache tables in the future), I would like to have 2 different Base classes
representing the two ways in which we would query the table. The obvious
way of doing this doesn't work:
class IssueUser(Base):
__tablename__ = 'issue_user_tag'
class IssueTag(Base):
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/sqlalchemy/-/ndCZzf-8b_QJ.
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.