D
D
DuD2014-04-04 17:17:06
Yii
DuD, 2014-04-04 17:17:06

How to implement many to many search through link table in YII in standard search method?

Question in continuation of the existing one: MySQL - select from a many-to-many table

There is a table with the names of stores `mags`:
`mag_id`, `mag_name`
a table with goods that are sold there `tovs`:
`tov_id`, `tov_name`
and a linking table `mag_tov`:
`mt_mag_id`, `mt_tov_id`
Suppose there are products 'milk', 'sausage', 'meat', 'cheese', 'vodka', 'tea', 'coffee', 'salt'. Each store sells several different products at the same time.

nmike gave the answer:
SELECT mags.*, COUNT(*) AS c FROM mag_tov, tovs, mags WHERE mt_tov_id = tov_id AND mt_mag_id = mag_id AND tov_name IN ('milk', 'meat' and 'tea') GROUP BY mag_id HAVING c = 3

I have a similar situation, only the entities are different. Actually, the question is as follows. How to translate this query into AR YII language?
The bottom line is that I want to add this to the search method on the model.
There are already standard $criteria->compare(......) by fields. How to make such a request in addition to them?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question