In Cakephp 3, how to make has-many association follow inner join type for contain(). For matching(), i am getting duplicates and the result of association collection is not nested
Asked
Active
Viewed 2,183 times
0
-
You want to get data which at least one row of the associated table? If so you can put a where clause in which you can check the count from sub-query. This will behave like the inner join. Because as @ndm says "There is no such thing as INNER joined hasMany containments" – Aman Rawat May 05 '17 at 05:11
1 Answers
2
There is no such thing as INNER
joined hasMany
containments, as the CakePHP ORM will use an additional query to retrieve containments of that type.
If you get duplicates when using matching()
, then use distinct()
or group()
. If you need to retrieve associated records additionally to matching, then use contain()
too, and add conditions for the containment if necessary.
See also
- How to filter by conditions for associated models?
- Cookbook > Database Access & ORM > Query Builder > Filtering by Associated Data
- Cookbook > Database Access & ORM > Query Builder > Selecting Data
- Cookbook > Database Access & ORM > Query Builder > Passing Conditions to Contain
- API > \Cake\Database\Query::distinct()
- API > \Cake\Database\Query::group()