Hello,
I'm trying to automate a backref update. Basically, when a child model is inserted or updated I want the parent model's "updated_at" column to mutate. The value should be the approximate time the user-child-model was updated. The updated_at value would not have to match the created_at/updated_at value on the child. It would just need to mutate to a new time.
class UserModel(db.Model):
updated_at = db.Column(db.DateTime, default=db.now, onupdate=datetime.now)
class UserChildModel(db.Model):
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
user = db.relationship('UserModel', backref='children')
user = UserModel()
save(user)
print(user.updated_at) # x
child = UserChildModel(user_id=user.id)
save(child)
print(user.updated_at) # y (value changed)
Hopefully this pseudocode is sufficient.
I'm wondering if there is an option I can specify on the orm.relationship factory. Or will I need to define an event?
Thanks!