On 07/23/2016 01:34 PM, Ameretat Reith wrote:
I'm trying to make three `Guy', `Father' and `Father1980' models mapped
to two `guys' and `fathers' tables.  Fathers will inherit Guys and
Father1980 will inherit Fathers.  So I coded it as:

|
fromsqlalchemy import(Table,Binary,ColumnasC,String,Integer,
                        ForeignKey,create_engine,MetaData)
fromsqlalchemy.orm import(mapper,relationship,backref,scoped_session,
                            sessionmaker)

metadata =MetaData()
db_engine =create_engine('sqlite:////tmp/test.db',convert_unicode=True)
db_session =scoped_session(sessionmaker(bind=db_engine))

classGuy(object):
    pass

classFather(Guy):
    def__init__(self,birth):
        self.birth =birth
        super(Father,self).__init__()

classFather1980(Father):
    def__init__(self,*args,**kwargs):
        super(Father1980,self).__init__(1980,*args,**kwargs)

guys =Table('guys',metadata,
             C('id',Integer,primary_key=True),
             C('type',String,nullable=False)
)

fathers =Table('fathers',metadata,
                C('id',ForeignKey('guys.id'),primary_key=True),
                C('birth',Integer)
)

father80s =Table('fathers_80s',metadata,
                   C('id',ForeignKey('fathers.id'),primary_key=True),
                   C('birth',Integer)
)

guysMapper =mapper(Guy,guys,polymorphic_on=guys.c.type)

fathersMapper =mapper(Father,fathers,inherits=guysMapper,
                       polymorphic_identity='plain-father')

mapper(Father1980,fathers,inherits=fathersMapper,
       polymorphic_identity='young-father')

you have the wrong table above ("fathers" and not "fathers80s"). There's a bug here in how the ORM is corrupting the table in response to this which I'll fix separately.



File"/venv/lib/python2.7/site-packages/sqlalchemy/sql/expression.py",line 
2737,incorresponding_column
    ifself.c.contains_column(column):


This is a very old version of SQLAlchemy, as starting with the 0.9 series the expression.py module was refactored to not be 4000 lines long. If you're doing new ORM development and not just maintaining legacy code, I encourage you to upgrade to version 1.0.









File"/venv/lib/python2.7/site-packages/sqlalchemy/util/langhelpers.py",line
612,in__get__
    obj.__dict__[self.__name__]=result =self.fget(obj)

File"/venv/lib/python2.7/site-packages/sqlalchemy/sql/expression.py",line 
2812,incolumns
    returnself._columns.as_immutable()
AttributeError:'Table'objecthas noattribute '_columns'

|


If I map `Father1980' to table `fathers_80s' instead of table `fathers'
the error will go.  I guess mapper didn't see `guys.type' from
`fathersMapper'.  Can I make this working?

--
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
<mailto:sqlalchemy+unsubscr...@googlegroups.com>.
To post to this group, send email to sqlalchemy@googlegroups.com
<mailto:sqlalchemy@googlegroups.com>.
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 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