D
D
dadids2014-06-21 11:24:20
MySQL
dadids, 2014-06-21 11:24:20

How to filter by quantity in yii2?

Organized a selection from several tables (based on relations). It worked well, but there is one more task, you need to filter out those companies in which there are open vacancies. That is, if the company's vacancy count is greater than zero, then show this company.
Let me tell you a little about the project.
This is a work site. The site has vacancies and companies. A person registers, and creates two profiles, one for his other company. After can add vacancies. Companies are displayed separately vacancies separately.
Each vacancy has a uid field by which you can make a comparison. Like everything, if I answer questions.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Tarasenko, 2014-11-20
@STarasenko

Based on the date of the question, I will assume that it is no longer relevant, but suddenly someone needs it ...
What prevents you from making a condition in a connection?

'company'=>array(self::HAS_MANY, 'Company', 'company_id', 
'group' => 'company_id',
'having' => 'COUNT(company_id) > 0',
'condition'=>'is_active=1');

Sample code I tested on:
SELECT seller_id, COUNT(seller_id) FROM vsellers_categories GROUP BY seller_id HAVING COUNT(seller_id) > 0;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question