Hi,

I have a set up class inheritance using joined table inheritance. I'm using 
sqlalchemy 0.8.2.

The Parent class has a DateTime attribute "updated_at", with 
onupdate=datetime.utcnow.

If I update only one of the Child's attributes, only "child" table is 
updated, parent.updated_at is not changed. If I change one of the Parent's 
attributes, then updated_at is updated as expected. 

Here's my questions:
1) Am I missing something in my setup? is it normal or is it a bug?
2) If this is normal, what is the right way to tell session that 
"parent.updated_at" should be modified too?

Regards,
-- 
Bertrand

-- 
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 http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.
# coding=utf-8
"""
"""
from __future__ import absolute_import

from datetime import datetime

import sqlalchemy as sa
from sqlalchemy import Column, Integer, String, ForeignKey
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()
BaseMeta = Base.__class__

class Parent(Base):
    __tablename__ = 'entity'
    __mapper_args__ = {'polymorphic_on': 'entity_type',
                      'with_polymorphic': '*',
                       }
    entity_type =  Column('entity_type', String(1000), nullable=True)

    id = Column('id', Integer(), primary_key=True)
    name =  Column('name', String(1000), default=u'')
    updated_at = Column(sa.DateTime,
                        default=datetime.utcnow,
                        onupdate=datetime.utcnow)


class Child(Parent):
    __tablename__ = 'child'
    __mapper_args__ = {'polymorphic_identity': 'Child'}
    id = Column(Integer,
                ForeignKey('entity.id', name='fk_inherited_entity_id'),
                primary_key=True)

    text = Column('text', String(1000), default=u'')


def run():
    engine = sa.create_engine('sqlite:///:memory:', echo=True)
    Session = sa.orm.sessionmaker(bind=engine)
    session = Session()
    sa.orm.configure_mappers()
    Base.metadata.create_all(engine)

    obj = Child()
    session.add(obj)
    session.commit()

    # obj.update_at is not changed
    obj.text = 'some text'
    session.commit()

    # obj.name is changed, obj.updated_at is changed
    obj.name = u'test'
    obj.text = 'some text'
    session.commit()

if __name__ == '__main__':
    run()

Reply via email to