Edit: Cake version 2.7
In my app I have a Wedding model which has a HABTM relationship with Users. When I'm logged into as the admin user I want to be able to add a new Wedding and by doing so generate and save 2 additional users to login with different roles.
public $hasAndBelongsToMany = array(
'User' => array(
'className' => 'User',
'joinTable' => 'weddings_users',
'foreignKey' => 'wedding_id',
'associationForeignKey' => 'user_id',
'unique' => 'keepExisting',
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
)
);
Is my Wedding model and is replicated back on the User model.
When I run the basic create action I get this:
Array (
[Wedding] => Array
(
[name] => james and sally
[ceremony_date] => Array
(
[month] => 06
[day] => 26
[year] => 2015
[hour] => 02
[min] => 29
[meridian] => pm
)
[venue_id] => 1
)
[User] => Array
(
[User] =>
)
)
I can then Create Additional users using the $this->Wedding->User->create() method and putting them into the array. The Wedding saves, the users save (With problems more further on) however the association doesn't save. Even using the
$this->Wedding->saveAssociated($saveData)
method.
Additional Problem The beforeSave function doesn't seem to be called and my users are entered into the DB with blank passwords.
public function beforeSave($options = array()) {
if (isset($this->data[$this->alias]['password'])) {
$passwordHasher = new BlowfishPasswordHasher();
$this->data[$this->alias]['password'] = $passwordHasher->hash(
$this->data[$this->alias]['password']
);
}
return true;
}
I assume it's something to do with my $this->data array but I havn't got that far yet.
Any help would be appreciated.