Hi,
I’m new to OOP programming and programming with a framework. I’ve got a “best practice” type question:
I’m implementing the blog tutorial, but adding a “blog” table so there can be multiple blogs.
I’ve added a “last_activity” field to the blog table that I’d like to update with the current time whenever a post or a comment is saved.
So… in the post model, in the afterSave method, I’ve added this line, which works fine, because a particular instance of post has an “id_blog” attribute.
blog::model()->updateByPk($this->id_blog,array('last_activity'=>time()));
But, what’s the best way of implementing this in the comment model? There’s no id_blog attribute in the comment model, so I can’t do an updateByPk. I could do a SQL query joining on post to get id_blog, and then run the above code, but since so much seems to be “loaded” and “connected” in this framework, I’m wondering if there’s a better way, more “OOP/Framework” way to do this. How does the comment object know that, two relations away, it’s part of a blog - and does it have access to the id of that blog?
Thanks for your help.
-Charlie