On Dec 1, 2011, at 1:32 AM, Wubin wrote:
> Hi,
> I created two classes "Resource" and "BaseMedia", and "BaseMedia" is a
> subclass of "Resource". The table mapping is implemented as below:
>
> class Resource(Database.Base):
> __tablename__ = "resources"
> createUserId = Column("create_user_id", Integer,
> ForeignKey("users.id"), nullable=True, key="createUserId",
> default=currentUserId)
> modifyUserId = Column("modify_user_id", Integer,
> ForeignKey("users.id"), nullable=True, key="modifyUserId",
> default=currentUserId, onupdate=currentUserId)
>
> class BaseMedia(Resource.Resource):
> __tablename__ = "base_media"
> id = Column("id", Integer, ForeignKey("resources.id"),
> primary_key=True)
> __mapper_args__ = { 'extension':
> BaseMediaMapperExtension.BaseMediaMapperExtension() }
> name = Column("name", Unicode(50))
> type = Column("type", String(50))
> size = Column("size", Integer)
>
> and then, when I try to use session.add() to insert a new BaseMedia
> object, the parameter "default=currentUserId" in both "createUserId"
> and "modifyUserId" columns is working properly. However, if I use
> session.merge() to update the "name" column in an existing BaseMedia
> object, the "name" field is updated correctly in the database, but the
"name" is on the "base_media" table, not "resources", so no onupdate proceeds
when only columns against base_media are modified.
onupdate is mostly used for timestamp columns to log when a row was last
modified. Using it to set integer foreign key values seems pretty questionable.
--
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.