私は2つのテーブルを持っています:車とcar_types。車 "hasOne"タイプとタイプ "hasMany"車。私のモデルでこの制約を定義しましたが、以下のようなエラーメッセージを表示せずにコントローラまたはビュー内の値を読み取るにはどうすればよいですか?CakePHP 3 - 1054列が見つかりません
MySQLエラーメッセージ:
public function index() {
$query = $this->Cars->find('all', ['contain' => [
'CarTypes'
]]);
debug($query->toArray());
}
車のテーブル::
id - type_id - method_id
Car_typesテーブル
"Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'CarTypes.type_id' in 'on clause'"
私はCarsController内でこれを行うこのエラーを得ました:
id - type
CarTypesモデル:
public function initialize(array $config)
{
parent::initialize($config);
$this->setTable('car_types');
$this->setDisplayField('id');
$this->setPrimaryKey('id');
$this->hasMany('Cars', [
'foreignKey' => 'type_id'
]);
}
車モデル:
public function initialize(array $config)
{
parent::initialize($config);
$this->setTable('cars');
$this->setDisplayField('id');
$this->setPrimaryKey('id');
$this->hasOne('CarTypes', [
'className' => 'Cars.CarTypes',
'foreignKey' => 'type_id',
'propertyName' => 'type'
]);
}
'CarTypes'のための' Cars.CarTypes'、 –
を変更しても同じエラーが発生します。 – CodeWhisperer