私はcustomersテーブル、contactsテーブル、contacts_customers joinテーブルを持っています。これにはcontact_typeテーブルにマップされるcontact_type_idフィールドもあります。私はCakePHP update extra field on HABTM join tableにリンクされている情報を使って解決策を試してみましたが、部分的にしか働いていません。私は2つの部分が保存ContactCustomersController
CakePHP HABTM JoinTable/Extraフィールド
$this->ContactsCustomer->Contact->save($this->data);
$this->ContactsCustomer->create();
if ($this->ContactsCustomer->save($this->data,
array('validate' => 'first'))) {
$this->Session->setFlash(__('The contacts customer has been saved', true));
$this->redirect(array('controller' => 'contacts_customers', 'action' => 'index'));
} else {
$this->Session->setFlash(__('The contacts customer could not be saved. Please, try again.', true));
}
に注意して
add()
方法を変更し、これは、
ContactsCustomer
モデルの
saveAll()
メソッドを使用すると問題が発生していないため、結果のページのSQLログに表示されたすべてが
BEGIN
の直後に
ROLLBACK
の順で表示されていたためです。私の前提は、これは
contacts
テーブルと
contacts_customers
テーブルの間の外部キー制約によるものであったので、2部構成の保存を選択しました。
いずれの場合も、現在のコードではエラーは報告されませんが、結果として適切な情報がcontacts
テーブルに保存されますが、contacts_customers
の結合テーブルには何も保存されません。投稿されたデータは、FireBugのログデータに従って適切であるように見えます。
_method POST
data[Contact][address_1] asdsad
data[Contact][address_2]
data[Contact][city] asdasd
data[Contact][email] [email protected]
data[Contact][fax]
data[Contact][first_name] Joe
data[Contact][last_name] Blow
data[Contact][mobile_phon...
data[Contact][office_phon... sdfsdfdf
data[Contact][postal_code... 121212
data[Contact][state] asdas
data[Contact][title]
data[ContactsCustomer][ContactType]
data[ContactsCustomer][ContactType][] 1
data[ContactsCustomer][ContactType][] 2
data[ContactsCustomer][ContactType][] 3
data[ContactsCustomer][Customer] 1
私はここで間違って何をしましたか?提供された援助のおかげで多くの!
関連モデルデータ:
contact.php
var $hasMany = array(
'ContactsCustomer'
);
contact_types.php
var $hasMany = array(
'ContactsCustomer'
);
customer.php
var $hasMany = array(
'ContactsCustomer'
);
contacts_customer.php
var $belongsTo = array(
'Contact', 'ContactType', 'Customer'
);
ありがとうございましたが、 '$ this-> data'の内容には、そのサブアレイも含めてメモの変更はありません。 私はまだ複数の道を調査中です。 – user846764