On 06/14/2016 11:28 AM, Ken Linehan wrote:
Hello,

I'm working with a class inheritance structure which can be illustrated
by this example:
|
class Entity(object):

  def __init__(self,
    entity_type=EntityTypeEntity,
    id=None):

      self.entity_type = entity_type
      self.id = id

class Person(Entity):

  def __init__(self,
    entity_class=None,
    entity_type=EntityTypePerson,
    id=None,
    name_first=None,
    name_last=None,
    name_middle=None,
    name_prefix=None,
    name_suffix=None):

      super(Person, self).__init__(entity_type,
                                   id)

      self.entity_class = entity_class
      self.name_first = name_first
      self.name_last = name_last
      self.name_middle = name_middle
      self.name_prefix = name_prefix
      self.name_suffix = name_suffix

class SupporterPerson(Person):

  def __init__(self,
    entity_class=EntityClassSupporterPerson,
    entity_type=EntityTypePerson,
    id=None,
    name_first=None,
    name_last=None,
    name_middle=None,
    name_prefix=None,
    name_suffix=None,
    relationship=None):

      super(SupporterPerson, self).__init__(entity_class,
                                            entity_type,
                                            id,
                                            name_first,
                                            name_last,
                                            name_middle,
                                            name_prefix,
                                            name_suffix)

      self.relationship = relationship
|

My current mappings look like this:
|
# Mappers
self.entity_table_mapper = mapper(
  Entity,
  self.entities_table,
  polymorphic_on=self.entities_table.c.entity_type,
  polymorphic_identity=EntityTypeEntity,
  with_polymorphic='*',
  properties={
    'entity_type': self.entities_table.c.entity_type,
    'id': self.entities_table.c.id,
  }
)

self.persons_table_mapper = mapper(
  Person,
  self.persons_table,
  polymorphic_on=self.persons_table.c.entity_class,
  polymorphic_identity=EntityTypePerson,
  with_polymorphic='*',
  inherits=Entity,
)

self.supporter_persons_table_mapper = mapper(
  SupporterPerson,
  self.supporter_persons_table,
  polymorphic_identity=EntityClassSupporterPerson,
  with_polymorphic='*',
  inherits=Person,
)
|

I am able to instantiate a SupporterPerson() and successfully store all
attributes correctly in their respective tables. So the mapping seems to
work well. However...

what's likely happening is that you're attempting to use two levels of polymorphic_on which isn't supported right now. a load of Entity will only consider those classes it can identify via entity_type.

There's a fairly elaborate proof of concept for this feature at https://bitbucket.org/zzzeek/sqlalchemy/issues/2555/cascading-polymorphic-ons , I've just re-reviewed it and it should still work.





In the broader context of my application, a query to load Causes() (
sketched out below ) will eagerload a list of that causes supporters.
 When supporters are eagerloaded, the supporter is reliably loaded to
the level of Person() however the attributes specific to
SupporterPerson() are not loaded.  In other words, the attributes
specific to the youngest child in my class inheritance, structure are
NOT loaded by the eagerload.

|
class Cause(object):

  def __init__(self,
    id=None
    supporters=None):

      self.id = id
      self.supporters = [] if supporters is None else None
|

So my question is, Is there a problem with my mapping? Or is this depth
of inheritance not supported by the eagerload? Or perhaps there is
something else I'm missing altogether ( unrelated to the eagerload ) ?
Any advice or assistance would be greatly appreciated. Sorry if I'm
missing something that is already clearly stated in the documentation.

Best,

Ken

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

--
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.

Reply via email to