> I have no idea what you are trying to accomplish. Why not use
> joined inheritance normally? When you query for Employee, you will
> get Engineer / Manager objects back, they will have .name.
>
> If you're trying to make it so that only one SELECT is emitted in
> order to get fully populated Engineer/Manager, joined inheritance
> already does that as well, use plain with_polymorphic for that, the
> SQL is constructed automatically.
Sorry, I haven't done a good job of explaining my use-case very well. I
want to be able to treat the name from both Engineer and Manager as the
same thing on Employee, so that I can write queries like:
session.query(Employee.name)
and also:
session.query(Employee)
Joined inheritance lets you do that if you put the name on the
employee, but I'd like to keep the name on the individual subtypes. For
my actual use case, some of the columns on one of the subtypes is
calculated from other bits of SQL: in other words, the way the columns
are written out in SQL needs to differ for each type, but I'd like to
be able to write queries to select the columns without having to
explicitly write out the union each time.
So for better motivation, imagine if Engineer.name was defined as:
@hybrid_property
def name(self):
return "E" + str(self.id)
@name.expression
def name(cls):
return ("E" + cls.id.cast(String())).label("name")
while Manager.name remains an ordinary column.
--
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.