モデルの関連付けを手伝ってください。スキーマは次のようになります。
translation_typeofs.typeof_idはtypeof_[name]外部キーです
translation_typeofs.typeof_typeコンテンツリレーションテーブルの名前の一部(日、色、建物、または部屋)。
TypeofDaysモデル:
class TypeofDay extends AppModel {
public $name = 'TypeofDay';
public $hasMany = array(
'GalleriesTypeofDay' => array(
'className' => 'GalleriesTypeofDay',
'dependent' => true
),
'TranslationTypeof' => array(
'className' => 'TranslationTypeof',
'conditions' => array('TranslationTypeof.typeof_type' => 'days'),
'dependent' => true
)
);
}
TranslationTypeofモデル:
class TranslationTypeof extends AppModel {
public $name = 'TranslationTypeof';
public $belongsTo = array(
'Language' => array(
'className' => 'Language',
'foreignKey' => 'language_id',
),
'TypeofBuilding' => array(
'className' => 'TypeofBuilding',
'foreignKey' => 'typeof_id',
'conditions' => array('TranslationTypeof.typeof_type' => 'buildings')
),
'TypeofColour' => array(
'className' => 'TypeofColour',
'foreignKey' => 'typeof_id',
'conditions' => array('TranslationTypeof.typeof_type' => 'colours')
),
'TypeofRoom' => array(
'className' => 'TypeofRoom',
'foreignKey' => 'typeof_id',
'conditions' => array('TranslationTypeof.typeof_type' => 'rooms')
),
'TypeofDay' => array(
'className' => 'TypeofDay',
'foreignKey' => 'typeof_id',
'conditions' => array('TranslationTypeof.typeof_type' => 'days')
)
);
}
データを保存しようとすると
$this->TranslationTypeof->saveAll(array(
'typeof_type' => $this->data['type_name'],
'typeof_id' => $this->data['type_id'],
'language_id' => $languageId,
'text' => $translation
));
エラー500(内部サーバーエラー)が発生します
エラーログ:
エラー:[PDOException] SQLSTATE [23000]:整合性制約違反:1452子行を追加または更新できません:外部キー制約が失敗します(schema
。translation_typeofs
、CONSTRAINT translation_typeofs_typeof_buildings_fkid1
FOREIGN KEY(typeof_id
)REFERENCES typeof_buildings
(id
)ON DELETE NO ACTION ON UPDATE NO ACTION)
モデルの関連付けがあると思いますが、解決策が見つかりません。