The key point is that the derived class needs a pointer to its base
class for the inheritance, and if it has another one to represent object
linkage, then the ORM module doesn't know which one is which, in my case
even though they were all called node_id, the fact one of the classes
had another reference it didn't know which to use, thus you need to put
a __mapper_args__ with an entry for "inherit_condition" to indicate
which on to use for inheritance. Once you resolve the inheritance
problem, the rest can be used for object relationships.

On 9/8/20 4:50 PM, [email protected] wrote:
> I'm having the same problem,
> I have a base class called TrackedEntity that has child classes like
> Request and others that inherit from it
>
> on Request I wanted to put a reference to the id of the TrackedEntity
> that created the Request
> class Request(TrackedEntity, TrackedEntityContainer, VisibleIdMixin):
>      parent_tracked_entity_id = Column(UUID,
> ForeignKey("tracked_entity.id"))
>
> and I get the same error as above.  Adding that inherit condition
> makes the runtime error stop, but it doesn't make sense to me. Why
> can't I just have a foreign key to that table? It's a simple many to one
>
>
> @Richard: you can use @declared_attr.cascading to cascade the
> mapper_args to your child classes.
> On Friday, August 28, 2020 at 2:56:02 PM UTC-4 Richard Damon wrote:
>
>     Thank you, so that go into each subclass that would have the problem.
>
>      8/28/20 2:37 PM, Mike Bayer wrote:
>     > the argument you're looking for is inherit_condition:
>     >
>     >
>     
> https://docs.sqlalchemy.org/en/13/orm/mapping_api.html#sqlalchemy.orm.mapper.params.inherit_condition
>
>     >
>     >
>     > class Foo(...):
>     >    __mapper_args__ = {
>     >       "inherit_condition": node_id == Node.node_id
>     >    }
>     >
>
>     -- 
>     Richard Damon
>

-- 
Richard Damon

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/8f002a3f-fb68-5f8b-c921-2dddaceb1119%40Damon-Family.org.

Reply via email to