Hi Mike,
Thanks for the quick reply. I added the "concrete=True" to the B class
definition and got this error:
AttributeError: Concrete Mapper|B|b does not implement attribute 'type' at
> the instance level. Add this property explicitly to Mapper|B|b.
Although is a subclass of A (as defined above), the "type" relationship
appears lost. OK, I'll add it back to the B definition:
type_pk = Column("type_pk", Integer, ForeignKey(Type.pk))
type = relationship(Type, primaryjoin=Type.pk==type_pk)
I used the same label for "backref" initially and got a "property of that
name exists" error. I them omitted the backref as above.
This works exactly as I'd hoped! I create a B object, it's inserted into
the database as expected (visible in the A and B tables). When I perform a
query to retrieve all A objects, the correct number is returned and some of
them are correctly typed B. The defined relationships work. I tried
creating a "backref" with a unique name, and that worked, but I found that
wasn't necessary if I'm happy using the same name. When going from the type
mapped to A, I get a list of A objects (excluding B); when going from the
type of B, I get the list of just the B objects.
Is there a way to set the type_pk discriminator in the B class as a default
so I don't have to set it every time?
Thanks!
Demitri
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable
Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.