Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAndras Andras
8,230 PointsPython, SQLAlchemy cascade - save-update
Hi there,
I would like to ask if it is possible to update the Child records automatically when Parent is changing in a one-to-many relationship.
For example; I have a task list for every project at the company:
Project 1 (Parent table)
-> Project 1 - Task1 (Child table)
-> Project 1 - Task2
-> Project 1 - Task3
Project2
-> Project 2 - Task1
-> Project 2 - Task2
-> Project 2 - Task3
I want to change the project name from "Project 1" to "Project First" in the Parent table. How can I achieve to update the name of the project in the Child table as well?
1 Answer
Steven Parker
231,261 PointsYou used the term in your title .. what you want is a cascade update. But I think you will need to enable that directly in the database engine you are using, if it supports it. And it most likely needs to be established at the same time the foreign key is. Check the documentation for your database.