나는 다음과 같은 DB 구조를 만들기 위해 노력하고 있습니다 :CakePHP 3 - 다른 테이블을 통해 테이블 조인?
sales_transaction
products
- : 특히
http://www.databaseanswers.org/data_models/generic_pos/index.htm
을, 나는 사이의 관계에서 찾고내가
sales_transaction
DB에 전화를 걸거나 다음 바로products
를 포함 할 수 있도록
나는, 관계 설정을 원하는, 그리고 한 쿼리에서 모든 것을 가져옵니다.
public function initialize(array $config)
{
parent::initialize($config); // TODO: Change the autogenerated stub
$this->belongsToMany('SalesTransaction', [
'through' => 'ProductsInTransaction'
]);
}
ProductsTable
SalesTransactionTable
public function initialize(array $config)
{
parent::initialize($config); // TODO: Change the autogenerated stub
$this->hasMany('Products', [
'through' => 'ProductsInTransaction'
]);
}
: 그러나, 그냥 아닌가요 작업, 그래서 :-) 여기에
내 코드입니다 저를 도와주세요 제품 거래 테이블public function initialize(array $config)
{
parent::initialize($config); // TODO: Change the autogenerated stub
$this->belongsTo('SalesTransaction', [
'foreignKey' => 'transaction_id',
'joinType' => 'inner'
]);
$this->belongsTo('Products', [
'foreignKey' => 'product_id',
'joinType' => 'inner'
]);
}
관계는 위의 진술에서 명백해야한다. 본질적으로 SalesTransaction
에는 모든 거래가 포함되어 있으며 products_in_transaction
은 products
과 연결하기위한 내 조인 테이블이지만 전체 구성표를 보려면 링크를 참조하십시오.
내가 그것을 가져 오기 위해이 코드를 실행하려고하면 :
$sales_transactions = $sales_transactions_table->find('all', [
'conditions' => [
'device_id IN' => $deviceIdsInDepartment
],
'contain' => [
'Products'
]
]);
내가이 오류 : 당신은 당신의 SalesTransaction
모델의 hasMany
연결을 사용하고
정말 우리에게 아무것도 알 수 없다 "그냥 작업하는 아닌가요"
IT는
belongsToMany
해야한다. 당신이 가진 문제는 무엇입니까? 여기에는 의문의 여지가 없습니다. – cgTag나는 성명에 비해 케이크에 관계가 설정되어 있는지 확인해야합니다. 더 이상 2 초를 더합니다. –
추가 정보 –