Created
February 24, 2016 18:12
-
-
Save syammohanmp/0990a2f1010f666d1c16 to your computer and use it in GitHub Desktop.
Save HABTM relationships CakePHP 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
App::uses('Model', 'Model'); | |
class AppModel extends Model { | |
public function beforeSave($options = array()) { | |
// save our HABTM relationships | |
foreach (array_keys($this->hasAndBelongsToMany) as $model){ | |
if(isset($this->data[$this->name][$model])){ | |
$this->data[$model][$model] = $this->data[$this->name][$model]; | |
unset($this->data[$this->name][$model]); | |
} | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment