Skip to content

Instantly share code, notes, and snippets.

@syammohanmp
Created February 24, 2016 18:12
Show Gist options
  • Save syammohanmp/0990a2f1010f666d1c16 to your computer and use it in GitHub Desktop.
Save syammohanmp/0990a2f1010f666d1c16 to your computer and use it in GitHub Desktop.
Save HABTM relationships CakePHP 2
<?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