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
> parameter "onupdate=currentUserId" is not firing, and therefore I
> couldn't update the "modifyUserId" field with this "onupdate"
> parameter.

Do you see an UPDATE occurring in the logs ?   The UPDATE statement should 
include a SET clause for the modifyUserId column unconditionally - the value in 
the parameter list might shed some light on what's actually happening.

Particularly with merge(), the value from the merged object is likely being 
passed as the new value of modifyUserId and that's what's being used.


-- 
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.

Reply via email to