the afterSave function is called after each separate save in the saveAll execution, so you can: In the AppModel
class AppModel extends Model { var $inserted_ids = array(); function afterSave($created) { if($created) { $this->inserted_ids[] = $this->getInsertID(); } return true; } }
You can put this code in any model, and it should work fine. Then, to return the identifiers after saving to the controller, you will do this:
if($this->Post->saveAll($posts)) { $post_ids=$this->Post->inserted_ids;
Hope this helps
source share