I think the code is correct and is behaving correctly also -- since you update just the child, the parent isn't touched (it already has data and was not changed in this session).

What you could do is add an update event to your Child object:


*def update_child(mapper, connection, target):**
**    # target is your child updated**
** target.parent.updated_at = datetime.datetime.now() # assuming you have mapped parent as a backref object or something**
**    object_session(target).commit()**
**
**event.listen(Child, 'after_update', update_child)**
*

If you want the same after an insert or delete, you should declare other events[1] as well. I think there might be other ways to do that, but I usually use events for its flexibility.

You can also use before_update to use the same session.commit()

[1] http://docs.sqlalchemy.org/en/rel_0_8/orm/events.html

Best regards,
Richard.

On 11/08/2013 08:38 AM, Bertrand Mathieu wrote:
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.

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

Reply via email to