Is it possible to specify a discriminator column from another table? How do I do this with Declarative?
The reason for this is I have a joined table inheritance with
class User(Base):
id = Column(...)
class Customer(User):
customer_id = Column('id', ...)
class Mechanic(User):
mechanic_id = Column('id', ...)
class Role(Base):
id = Column(..)
but want to discriminate by Roles a user has. A user could have a buyer role or a seller role or both.
Is this the correct way to model this scenario?
As a note, there is Buyer specific data and Seller specific data as well, and that is why I am using the joined table inheritance.
Here’s an awkward and inefficient way to achieve the specific result, which will also fail if more than one Role is present on the target User:
Next, here is how I would actually do it, if I had the issue of assigning behaviors based on zero or more Roles – I’d put the behavior in the Role, not the owner of the Role:
The second example produces the output:
As you can see the second example is clear and efficient while the first is just a thought experiment.