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?

<<<<<<<<<<< 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 sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to