Log message #4223703

# At Username Text
# Jan 23rd 2020, 20:45 k4t on results set or database?
# Jan 23rd 2020, 20:45 ndm That is expected, you need to use grouping.
# Jan 23rd 2020, 20:45 k4t that array should contain only 1 Post not 397
# Jan 23rd 2020, 20:44 k4t each Post in that array is exactly the same post but with different Comment under _matchingData key
# Jan 23rd 2020, 20:44 k4t imagine that PdfPlace is Post on that screen
# Jan 23rd 2020, 20:43 slackebot <k4t>
# Jan 23rd 2020, 20:42 k4t I agree, but I think that matching still should return results like ->contain instead of creating weird _matchingData key with associated data
# Jan 23rd 2020, 20:38 ndm When using matching on hasMany or belongsToMany you need to use grouping to avoid duplicates, that's the way to go
# Jan 23rd 2020, 20:38 ndm Matching is really just for filtering based on associated data, not for retrieving associated data. And using separate queries is just how the ORM works.
# Jan 23rd 2020, 20:38 k4t my hair is getting gray becuase of that
# Jan 23rd 2020, 20:37 ndm On a serious note
# Jan 23rd 2020, 20:37 ndm You need to be more open for new experiences :P
# Jan 23rd 2020, 20:36 k4t @ndm do you know what my problem is?
# Jan 23rd 2020, 20:35 k4t group by on DB is not needed
# Jan 23rd 2020, 20:34 challgren Im not sure though try both
# Jan 23rd 2020, 20:33 challgren database,
# Jan 23rd 2020, 20:33 k4t groupBy on database or returned ResultsSet?
# Jan 23rd 2020, 20:32 challgren groupBy()?
# Jan 23rd 2020, 20:31 k4t $results will contain a lot of duplicated items (Posts), and each Post in that array will contain Comment under _matchingData
# Jan 23rd 2020, 20:30 k4t which is a big pain for me
# Jan 23rd 2020, 20:30 k4t so ->matching is fine, it will give me SQL query which I want but result of association collection is not nested in $results array
# Jan 23rd 2020, 20:28 challgren Sorry jumping ahead
# Jan 23rd 2020, 20:28 challgren Ahh ok
# Jan 23rd 2020, 20:28 k4t and these additional queries added by ->contain are completely unnecessary as I already got all required data from db thanks to ->matching
# Jan 23rd 2020, 20:28 challgren You would need to do ->contain([‘Comments’ => function($q) { return $q->where([‘Comments.user_id’ => 2]) }])
# Jan 23rd 2020, 20:27 challgren It contains all the comments
# Jan 23rd 2020, 20:27 k4t but my problem is that results from ->matching are formated different then if I use ->contain
# Jan 23rd 2020, 20:26 challgren True
# Jan 23rd 2020, 20:26 k4t if I add contain it will again generate additional queries
# Jan 23rd 2020, 20:26 challgren Are you missing a contain()?
# Jan 23rd 2020, 20:25 k4t let me explain
# Jan 23rd 2020, 20:25 k4t It will, and it will generally generate query which interests me but my problem is that $results now contain data in "bad" format
# Jan 23rd 2020, 20:25 challgren Ahh theres the ORM expert
# Jan 23rd 2020, 20:25 ndm it will
# Jan 23rd 2020, 20:24 challgren Im not sure on that one
# Jan 23rd 2020, 20:23 k4t let's say we have relation Posts hasMany Comments and I will do: $results = $posts->find()->matching('Comments', function($q) { return $q->where(['Comments.user_id' => 2]) })->toArray(); It will generate 1 SQL query with INNER JOIN, right?
# Jan 23rd 2020, 20:20 challgren Im not an ORM expert by any means but Ill try to help my best
# Jan 23rd 2020, 20:17 k4t you are right but hmm... generally I have a big problem with CakePHP ORM and I can not solve it from years... let me write some details (sec)
# Jan 23rd 2020, 20:15 challgren For example your hasMany is Comments, and you have a Post, with what your talking about you would have 30 duplicate Posts for the 30 comments
# Jan 23rd 2020, 20:14 challgren And not duplicating the original data
# Jan 23rd 2020, 20:14 challgren How would you do it in regular SQL without 2 queries?