I might be getting a bit ambitious here, But is this possible?

I'm using a different polymorphic_on for the second level of
inheritance.

I tried it but it only seems to polymorphicly return records of type
_UtConfReconcilerActions


class _UtConfActions(Base):

        __tablename__ = 'tblActions'

        # 1 to Many relationship to the managed
        id = Column(Integer, primary_key=True)
        managed_id = Column(Integer, ForeignKey('tblManagedDetails.id'))
        component = Column(String)

        __mapper_args__ = {'polymorphic_on': component, 'with_polymorphic':
'*'}


class _UtConfReconcilerActions(_UtConfActions):

        __tablename__ = 'tblReconcilerActions'

        # 1 to Many relationship to the managed
        id = Column(Integer, ForeignKey('tblActions.id'), primary_key=True)
        action = Column(String)

        __mapper_args__ = {'polymorphic_identity': 'RECONCILER',
'polymorphic_on': action, 'with_polymorphic': '*'}




class _UtConfReconcilerActionSnapshot(_UtConfReconcilerActions):

        __tablename__ = 'tblReconcilerActionSnapshot'
        __mapper_args__ = {'polymorphic_identity': 'SNAPSHOT'}

        # Joined table inheritence
        id = Column(Integer, ForeignKey('tblReconcilerActions.id'),
primary_key=True)

        revision = Column(String)
        comment = Column(String)



On Sep 17, 10:48 am, Jarrod Chesney <[email protected]> wrote:
> That worked, Thanks, ITS AWESOME :-)
>
> On Sep 17, 6:03 am, Conor <[email protected]> wrote:
>
>
>
> > On Sep 15, 11:03 pm,Jarrod Chesney<[email protected]> wrote:
>
> > > Hi All
> > > I've been reading the documentation for ages and i can't figure out
> > > why when i print the results a query from my inherited table, It just
> > > prints them as the base type.
>
> > > I was hoping someone here would be nice enough to help me solve this
> > > problem.
>
> > > I thought the last print statement would print an instance of the
> > > _UtConfReconcilerActionSnapshot class but it doesn't
>
> > > I've got one record in both tables and 'id' = 1 in each table.
> > > What am i doing wrong?
>
> > You are missing "polymorphic_on" in
> > _UtConfReconcilerActions.__mapper_args__. Without this, SQLAlchemy
> > cannot do polymorphic loads. Try this as your __mapper_args__:
> > {'polymorphic_on': 'object_type', 'with_polymorphic': '*'}
>
> > Hope it helps,
> > -Conor
>
> > > <<<<<<<<<<< Begin code >>>>>>>>>>>>>
>
> > > from sqlalchemy import Table, Column, Integer, String, MetaData,
> > > ForeignKey, CheckConstraint
> > > from sqlalchemy.orm import relation
> > > from sqlalchemy.ext.declarative import declarative_base
> > > from sqlalchemy import create_engine
> > > from sqlalchemy.orm import sessionmaker
>
> > > __DATABASE_NAME__='UtConfSom.sqlite'
>
> > > Base = declarative_base()
>
> > > # ============================== Reconciler Actions
> > > ===========================
>
> > > class _UtConfReconcilerActions(Base):
>
> > >         __tablename__ = 'tblReconcilerActions'
> > >         __mapper_args__ = {'with_polymorphic': '*'}
>
> > >         # 1 to Many relationship to the managed
> > >         id = Column(Integer, primary_key=True)
> > >         action = Column(String, CheckConstraint("action in ('SNAPSHOT',
> > > 'COMPARE', 'UPGRADE')"))
> > >         object_type = Column(String, CheckConstraint("object_type in 
> > > ('ALL',
> > > 'SCHEMA', 'TABLE', 'COLUMN', 'INDEX')"))
>
> > >         def __repr__(self):
> > >                 return ("'%s'" % _UtConfReconcilerActions.__name__
> > >                             + "\n  id='%i'" % self.id
> > >                             + "\n  managed_id='%i'" % self.managed_id
> > >                             + "\n  action='%s'" % self.action
> > >                             + "\n  object_type='%s'" % self.object_type
> > >                             )
>
> > > class _UtConfReconcilerActionSnapshot(_UtConfReconcilerActions):
>
> > >         __tablename__ = 'tblReconcilerActionSnapshot'
> > >         # __mapper_args__ = {'with_polymorphic': '*'}
> > >         __mapper_args__ = {'polymorphic_identity': 'snapshot',
> > > 'with_polymorphic': '*'}
>
> > >         # Joined table inheritence
> > >         id = Column(Integer, ForeignKey('tblReconcilerActions.id'),
> > > primary_key=True)
>
> > >         revision = Column(String)
> > >         comment = Column(String)
>
> > >         def __repr__(self):
> > >                 return (_UtConfReconcilerActions.__repr__(self)
> > >                             + "\n  '%s'" % 
> > > _UtConfReconcilerActionSnapshot.__name__
> > >                             + "\n  id='%s'" % self.revision
> > >                             + "\n  revision='%s'" % self.revision
> > >                             )
>
> > > __db_exists = os.path.exists(__DATABASE_NAME__)
>
> > > engine = create_engine('sqlite:///' + __DATABASE_NAME__)
>
> > > # New database, create the tables
> > > if not __db_exists:
> > >         Base.metadata.create_all(engine)
> > >         print >> sys.stderr, ("WARINING - Creating empty '%s' database" %
> > > __DATABASE_NAME__ )
>
> > > Session = sessionmaker(bind=engine)
> > > session = Session()
>
> > > print session.query(_UtConfReconcilerActions).with_polymorphic
> > > ('*').first()
>
> > > <<<<<<<<<<<<<< end code >>>>>>>>>>>>>>>>>>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to