私は大きな成功を収めずにsaveAssociated
メソッドを使用しようとしてCakePHP
います。メソッドは部分的に機能しているようです。実際には、保存プロセスに3つのモデルがあります:
、これCharacter
はモデルです:$hasMany
Property
Label
Character
class Character extends AppModel {
public $name = 'Character';
public $belongsTo = 'User';
public $hasMany = array (
'Property' => array (
'dependent' => true
)
);
public $hasOne = array (
'Label' => array (
'dependent' => true
)
);
public $validate = array (
'name' => array (
'required' => true,
'rule' => array('between', 0, 100),
'message' => 'This is the error message for "name" field'
),
'description' => array (
'allowEmpty' => true,
'rule' => array('between', 0, 100),
'message' => 'This is the error message for "description" field'
)
);
}
これは、フォームから取得したデータです。
array(
'Character' => array(
'name' => 'Character name',
'description' => 'Character description',
'image' => 'http://url.com/image.jpg'
),
'Label' => array(
'name' => 'Basic attributes',
'value' => 'Value'
),
'Property' => array(
(int) 0 => array(
'name' => 'Strenght',
'value' => '15'
)
)
)
次に、私はデータCharactersController
に対してこれを行いsaveAssociated
ます:
class CharactersController extends AppController {
public $uses = array ('Character', 'Property', 'Label');
public function add () {
if (!empty($this->request->data)) {
$this->Character->saveAssociated($this->request->data);
}
debug ($this->request->data);
}
}
Character
データは正常に保存されますが、そうではありません。Label
どこProperty
が間違っていますか?