Eagleamon wrote:
> Hi all,
>
> I'm playing around with sqlalchemy for a new project and it's really
> great :) ... up to now.
> I'm in front of a problem:
>
> let's say I have several classes:
>
> class ParameterDefinition(Base):
> __tablename__ = "ParameterDefinitions"
> __table_args__ = {'mysql_engine':'InnoDB'}
> Type = Column(Integer, nullable = False)
> ImplementingParameters = relation("Parameter", backref =
> "ParameterDefinition", cascade = "all, delete-orphan")
please take a look at the new mixin functionality present in 0.6 which is
designed for the purpose of defining "common" columns. You can't just
stick columns in your base class unfortunately.
http://www.sqlalchemy.org/docs/reference/ext/declarative.html#mix-in-classes
>
> class Parameter(Base):
> __tablename__ = "Parameters"
> __table_args__ = {'mysql_engine':'InnoDB'}
> __mapper_args__ = {'polymorphic_on': ParameterDefinition.Type}
>
> Id = Column(Integer, primary_key = True)
> PId = Column(Integer, ForeignKey("ParameterDefinitions.PId"),
> nullable = False)
>
> class BooleanParameter(Parameter):
> __mapper_args__ = {'polymorphic_entity':'0'}
>
> BooleanValue = Column(Boolean)
>
> class IntegerParameter(Parameter):
> __mapper_args__ = {'polymorphic_entity':'1'}
>
> IntegerValue = Column(Integer)
> IntegerBump = Column(Integer)
>
> class StringParameter(Parameter):
> __mapper_args__ = {'polymorphic_entity':'2'}
>
> StringValue = Column(String(256))
>
>
> Of course, this fails as in the polymorphism definition,
> ParameterDefinition.Type is not defined for Parameter.
>
> So the question is, how could I discriminate on the value of the
> result of a join to get the mapper to instanciate the correct object ?
>
> Thanks in advance for any advice!
>
> --
> 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.
>
>
--
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.