I've tried to following several examples, for instance this one: http://stackoverflow.com/questions/1337095/sqlalchemy-inheritance
It seems because i've multiple inheritances, my problem is more complex than this example, is anyone has an idea why ? Julien. On Mon, Sep 27, 2010 at 11:10 PM, Julien Iguchi-Cartigny <kart...@gmail.com> wrote: > But How can i do ? It seems i need to define the table in > AsbtractContainer but every time I've an error about already defined > column. > > Cheers, > > Julien. > > On Mon, Sep 27, 2010 at 10:30 PM, Michael Bayer > <mike...@zzzcomputing.com> wrote: >> >> On Sep 27, 2010, at 4:21 PM, Julien Iguchi-Cartigny wrote: >> >>> Thank you Michael. This solves the problem and... shows a new one. >>> >>> So this is my update CourseSet >>> >>> class CourseSet(Base,AbstractContainer): >>> >>> �...@classproperty >>> def __mapper_args__(self): >>> args = dict() >>> args.update(AbstractContainer.__mapper_args__) >>> args.update({'polymorphic_identity': >>> 'org.sakaiproject.coursemanagement.impl.CourseSetCmImpl'}) >>> return args >>> >>> Because there is several discriminant values, I need to create other ones: >>> >>> class CanonicalCourse(Base,AbstractContainer): >>> >>> �...@classproperty >>> def __mapper_args__(self): >>> args = dict() >>> args.update(AbstractContainer.__mapper_args__) >>> args.update({'polymorphic_identity': >>> 'org.sakaiproject.coursemanagement.impl.CanonicalCourseCmImpl'}) >>> return args >>> >>> >>> But this last one will fail, i've the following error message: >>> >>> sqlalchemy.exc.InvalidRequestError: Table 'CM_MEMBER_CONTAINER_T' is >>> already defined for this MetaData instance. Specify >>> 'useexisting=True' to redefine options and columns on an existing >>> Table object. >>> >>> I could use useexisting=True but i don't know if it's the right >>> solution. Any ideas ? >> >> that has to do with a Table() statement, or alternatively how you are >> configuring __table_name__, neither of which are indicated here, so you need >> to ensure that distinct table names are used whenever a table name is >> declared. >> >> >> >> >>> >>> Cheers, >>> >>> Julien. >>> >>> On Mon, Sep 27, 2010 at 1:02 AM, Michael Bayer <mike...@zzzcomputing.com> >>> wrote: >>>> >>>> On Sep 26, 2010, at 6:38 PM, Julien Iguchi-Cartigny wrote: >>>> >>>>> Hi, >>>>> >>>>> I'm trying to use polymorphic_on with several inheritances: >>>>> >>>>> engine = create_engine( >>>>> 'mysql://xxx:y...@localhost:3306/zzz?charset=utf8&use_unicode=0', >>>>> pool_recycle=3600, echo=True) >>>>> >>>>> Base = declarative_base() >>>>> >>>>> class AbstractPersistent(object): >>>>> version = Column('VERSION', Integer) >>>>> last_modified_by = Column('LAST_MODIFIED_BY', String(255)) >>>>> last_modified_date = Column('LAST_MODIFIED_DATE', Date) >>>>> created_by = Column('CREATED_BY', String(255)) >>>>> created_date = Column('CREATED_DATE', Date) >>>>> >>>>> class AbstractNamed(AbstractPersistent): >>>>> eid = Column('ENTERPRISE_ID', String(255)) >>>>> title = Column('TITLE', String(255)) >>>>> description = Column('DESCRIPTION', String(255)) >>>>> >>>>> class AbstractContainer(AbstractNamed): >>>>> __tablename__ = 'CM_MEMBER_CONTAINER_T' >>>>> id = Column('MEMBER_CONTAINER_ID',Integer,primary_key=True) >>>>> discriminator = Column('CLASS_DISCR', String(100)) >>>>> __mapper_args__ = {'polymorphic_on': discriminator } >>>>> >>>>> class CourseSet(Base,AbstractContainer): >>>>> __mapper_args__ = {'polymorphic_identity': >>>>> 'org.sakaiproject.coursemanagement.impl.CourseSetCmImpl'} >>>> >>>> AbstractContainer is not mapped, its a mixin, so its __mapper_args__ are >>>> not used until a subclass of Base is invoked, which starts up a >>>> declarative mapping. Your only mapped class then is CourseSet, which has >>>> its own __mapper_args__ , that override those of AbstractContainer - they >>>> are ignored. >>>> >>>> To combine __mapper_args__ from a mapped class with those of a mixin, see >>>> the example at >>>> http://www.sqlalchemy.org/docs/orm/extensions/declarative.html?highlight=declarative#combining-table-mapper-arguments-from-multiple-mixins >>>> . It uses __table_args__ but the same concept of creating a full >>>> dictionary of arguments applies for __mapper_args__ as well. >>>> >>>> >>>> >>>> -- >>>> You received this message because you are subscribed to the Google Groups >>>> "sqlalchemy" group. >>>> To post to this group, send email to sqlalch...@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. >>>> >>>> >>> >>> >>> >>> -- >>> "Trouble-a-cat limited" >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "sqlalchemy" group. >>> To post to this group, send email to sqlalch...@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. >>> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "sqlalchemy" group. >> To post to this group, send email to sqlalch...@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. >> >> > > > > -- > "Trouble-a-cat limited" > -- "Trouble-a-cat limited" -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@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.