It looks like I can keep the @declared_attr by using
"inherit_condition": cls.node_id == cls.__mro__[1].node_id
The __mro__[1] gets the leftmost (or only) parent class. As long as I
make sure that it the inheritance tree (and I wasn't planning on
multiple inheritance here) I should be ok.
On 9/3
yup that was the idea
On Thu, Sep 3, 2020, at 10:24 AM, Richard Damon wrote:
> I have a large number (around a dozen or more, and likely to grow) of
> derived classes, so I was hoping to cut down repetition with the
> @declared_attr.
> So, 3rd (or farther) derived classes need the inherit_conditi
I have a large number (around a dozen or more, and likely to grow) of
derived classes, so I was hoping to cut down repetition with the
@declared_attr.
So, 3rd (or farther) derived classes need the inherit_condition to point
to their immediate base. That does seem to remove the warning.
On 9/3/20 9
you might be able to use the declared_attr __mapper__ but you would need to
omit that erroneous inherit condition if the class is "Name". IMO it would be
easier to follow and understand by simply using explicit __mapper_args__ on
each class but this depends on what you're doing.
On Thu, Sep
I've tried taking my code and changing the ForeignKey to be to Node, and
that doesn't change the Warning.
Is the problem trying to DRY with the @declared_attr __mapper__?
On 9/2/20 11:29 PM, Mike Bayer wrote:
> well you are giving Name an inherit condition that conflicts with how
> you set up the
well you are giving Name an inherit condition that conflicts with how you set
up the foreign key.
Name.node_id FKs to Property.node_id
but then inherit condition is Name.node_id -> Node.node_id
There seems to be a little unsmoothness to actually being able to configure it
that way, that is,
Here is the code, note in all cases node_id are foreign key/primary_key
to a primary_key down the chain:
class Base:
"""Base Class for SQLAlchemy ORM Classes"""
@declared_attr
def __tablename__(cls):
"""Default the Table Name to the Class Name"""
return cls.__name__
there's an FAQ entry, a little bit dated but the general idea is still there,
at:
https://docs.sqlalchemy.org/en/13/faq/ormconfiguration.html#i-m-getting-a-warning-or-error-about-implicitly-combining-column-x-under-attribute-y
for joined table inheritance, where Name(Node) -> node_id are FK -> P
I am getting the following error:
SAWarning: Implicitly combining column Node.node_id with column
Name.node_id under attribute 'node_id'. Please configure one or more
attributes for these same-named columns explicitly.
In my case I am using poymorphic classes by joining with the ORM. Node
is the