2

I have a hasAndBelongsToMany relationship set up between my Post model and Tag model.

I want a beforeSave() method in my Tag model which will execute when tags are saved.

Problem is, in my controller I'm calling $this->Post->save($this->request->data); and it doesn't seem to fire the beforeSave() method in the Tag model, even though they have a relationship between them and tags do get saved along with the post.

I could put my logic in the beforeSave() method of the Post model, but then I'd have tag related logic in my Post model which doesn't seem right.

Is there a way to fire the beforeSave() method in my Tag model when a post gets saved?

4

1 回答 1

-1

您是否尝试过使用 saveAll?

$this->Post->saveAll($this->request->data);
于 2013-01-11T13:48:05.133 回答