saveAll で複数のモデルを検証しようとしています。最初のモデルの検証はトリガーされていますが、関連するモデルに関しては何も起こっていないようです。exit を配置して beforeValidate() および beforeSave() メソッドが呼び出されているかどうかを確認しようとさえしました。コードは通常どおり実行され続けます。
ContactDetails モデル:
<?php
class ContactDetails extends ContactAppModel {
public $actsAs = array("MapValidate");
public $hasMany = array(
'ProjectLocation' => array(
'className' => 'ProjectLocation',
'foreignKey' => 'project_id'
)
);
public $validate = array(
'name' => array(
'required' => array(
'rule' => array('notEmpty'),
'message' => 'Contact name is required'
)
),
'address1' => array(
'required' => array(
'rule' => array('notEmpty'),
'message' => 'Contact address 1 is required'
)
),
'email' => array(
'required' => array(
'rule' => array('notEmpty'),
'message' => 'Contact email is required'
),
'email' => array(
'rule' => array('email'),
'message' => 'Contact email format is not valid'
)
)
);
}
ProjectLocation モデル:
<?php
class ProjectLocation extends ContactAppModel {
public $actsAs = array("MapValidate");
public $belongsTo = array(
"ContactDetails" => array(
"className" => "ContactDetails",
"foreignKey" => "project_id"
);
);
public $validate = array(
'lat' => array(
'checkLocation' => array(
'rule' => array('checkMap', 'lat'),
'message' => 'One or more positions on the map are invalid.'
)
)
);
}
これは、保存しようとしている $this->request->data です。
Array
(
[ContactDetails] => Array
(
[id] => 1
[name] => PreeoStudios
[address1] => 4, Stivala Street
[address2] => Mosta, MST 3205
[address3] => Malta
[telephone] => 34562737
[email] => info@preeostudios.com
[fax] => N/A
[skype] => N/A
)
[ProjectLocation] => Array
(
[0] => Array
(
[lat] => 35.886277456343024
[lon] => 14.428907312499973
)
[1] => Array
(
[lat] => 35.886277456343024
[lon] => 14.528907312499973
)
)
)
saveAll 呼び出し:
$this->ContactDetails->saveAll($this->request->data, array('validate' => 'first'))
編集
また、関連付けられたモデルから検証ルールを削除し、beforeSave 関数に終了を入れようとしました...コードは実行を続けます
<?php
class ProjectLocation extends ContactAppModel {
public $actsAs = array("MapValidate");
public $belongsTo = array(
"ContactDetails" => array(
"className" => "ContactDetails",
"foreignKey" => "project_id"
);
);
public function beforeSave(){
exit;
}
public $validate = array(
);
}