У меня есть следующие таблицы:
customers[id, name, surname, phone, text, balance, created]
service_types[id, title, price, length, is_subscription, created, payment]
customer_service_types[id, customer_id, service_type_id, price, created]
И отношения:
ServiceTypesTable.php:
$this->hasMany('CustomerServiceTypes', [
'foreignKey' => 'service_type_id'
]);
CustomerServiceTypesTable.php:
$this->belongsTo('Customers', [
'foreignKey' => 'customer_id',
'joinType' => 'INNER'
]);
$this->belongsTo('ServiceTypes', [
'foreignKey' => 'service_type_id',
'joinType' => 'INNER'
]);
Это мой код прямо сейчас:
$customerServiceTypes = TableRegistry::get('CustomerServiceTypes');
$customers_count = $customerServiceTypes->find()
->select(['customer_id'])
->distinct()
->where(['service_type_id <>' => 3])->count();
Я хочу изменить его, чтобы проверить в where
предложение, если service_types.payment = 0
из соединения customer_service_types
и service_types
на
customer_service_types.service_type_id = service_types.id