내 DomainTypes view() 함수에 대한 내 DomainTypes 테이블의 하위 항목을 포함하려고하는데 "오류 : SQLSTATE [42S22] : 열을 찾을 수 없음 : 1054 알 수없는 열 '이라는 불편을 겪고 있습니다. Children.domain_type_id 'in'where clause ' "문제는 내 DomainTypes 테이블에 domain_type_id 열이 없다는 것입니다. 도메인 테이블 않습니다. 내 도메인 유형보기()에 대한 코드는 다음과 같습니다.연관 찾기 잘못된 테이블
public function view($id) {
if (!$id) {
throw new NotFoundException(__('Invalid DomainType'));
}
$domainType = $this->DomainTypes
->find()
->where(['DomainTypes.id' => $id])
->contain(['Parent', 'Children', 'Affiliates'])
->first();
$this->set(compact('domainType'));
}
내 설치에 대해 약간 설명합니다. 2 개의 테이블, 도메인 및 도메인 유형이 있습니다. 둘 다 Tree 비헤이비어를 사용합니다. 여기
는 도메인 표에 대한 초기화 코드 :public function initialize(array $config){
parent::initialize($config);
$this->displayField('name');
$this->addBehavior('Tree');
//Associations
$this->hasMany('Children', [
'className' => 'Domains',
]);
$this->belongsTo('Parent', [
'className' => 'Domains',
]);
$this->belongsTo('Affiliates');
$this->belongsTo('DomainTypes');
}
그리고 여기 DomainTypes 표에 대한 초기화 코드 :
public function initialize(array $config){
parent::initialize($config);
$this->displayField('name');
$this->addBehavior('Tree');
//Associations
$this->hasMany('Children', [
'className' => 'DomainTypes',
]);
$this->belongsTo('Parent', [
'className' => 'DomainTypes',
]);
$this->belongsTo('Affiliates');
$this->hasMany('Domains');
}
매우 유사하지만 분명히 클래스 이름은 사용할 정의하는 두 . Cakephp 3에서 내 DomainTypes 테이블에 domain_type_id 열이 있다고 가정하는 이유는 무엇입니까? 미리 감사드립니다!
내가 belongsTo 관계 만 사용한다면 의미가 있지만, hasMany는 childrens parent_id를 사용해야하기 때문에 "child_id"가되지 않아야합니다. parent_id와 child_id를 모두 갖고 있다면 데이터를 복제하고 사이트를 더 많은 문제로 여는 것입니다. 아니면 내가 어디로 가는지 이해하지 못하겠습니까? – MjGaiser
@MjGaiser 아니, 네 말이 맞다. 제대로주의를 기울이지 않고'child_id'가 없어야하고'domain_type_id '라는 이름의 FK를 생성하는 CakePHP가 실제로 올바른 것으로 보인다. 내 대답을 업데이 트하고 말도 안되는 소리를 제거합니다 :) – ndm