On Tue, May 22, 2018 at 3:48 PM, Demitri Muna <demitri.m...@gmail.com> wrote:
> 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?

I should probably get a complete version of your codes so I can try it
sometime, I would think that since this discriminator column is
already set, it should be getting populated (maybe redefine it in the
__mapper_args__ for "b" to this local copy of the column).

if none of that works then I'd hit it with a default or event, if it's
local to "b" then just place "default=<discrimiminator>" on the
column.  or if you need more control of the process use a
before_insert event.


>
> 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 sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to