开发者

before insert and after delete

开发者 https://www.devze.com 2023-02-05 02:44 出处:网络
i am somehow lost again in my beginners project. I am adding records for flights which have a takeoff and a landing time. So everytime i am inserting a flight oder deleting it (to edit is another ques

i am somehow lost again in my beginners project. I am adding records for flights which have a takeoff and a landing time. So everytime i am inserting a flight oder deleting it (to edit is another question) i would like to update the total airframe time on the particular aircraft (different model). Now there are several issues coming up like if i should do this with an afterSave/beforeDelete function开发者_运维技巧 in my model or if i should do it in any other way e.g. mysql trigger or even in my controller.

My main problem is that i have tried to gather all the infomation i need in my afterSave() and beforeDelete calls, and i have no idea how to get the data accessed there. Especially in the beforeDelete() call there seams the $this->data array to be empty, so that i can´t calculate the amount of time i have to substract from my total airframe time.

So the core of my question is more of a general nature, if this really is the right way to do it. Another thing which is coming across my mind, is the fact that if something goes wrong inbetween i fear to have an inconsitent airframetime but an already delete flight record.

i am thinking of doing it with a stored procedure or somehow else.

Many thanks for reading this, and maybe a hint of a more cakeish way to do it.

Best regards,

cdjw


have a look at how counterCache works in the core, sounds like this is what you need to do. It all happens in the model callbacks.

have a look through the code and see where this is called http://api.cakephp.org/class/model#method-ModelupdateCounterCache

0

精彩评论

暂无评论...
验证码 换一张
取 消