0

I am new to cakephp 3. Below is my code.

  $getFlags = $this->Posts->find('all')->contain(['Users', 'Flags.Users', 'Flags.FlagReasons', 'Flags.Users.Schools']);

output

{
        "id": 114,
        "title": "",
         "allow_comment": 0,
        "owner_id": 84,
        "created": "2016-04-08T04:41:08+0000",
        "status": 1,
        "flags": [],
        "user": {
            "id": 84,
             "profile_image": "bc7484cd8caad0de055f8d7ef15551f5.png",
            "is_active": 1
        }

Here i want to give a condition,when there is an empty flag ,it will not be listed in result. Only post having flag will come. Please suggest me. ANy suggstion will highly appreciate.

sradha
  • 2,216
  • 1
  • 28
  • 48

1 Answers1

0

There are two ways to get this done:

  • Use a counter cache and filter by that field (flag_count > 0)
  • Do a subquery to get the count (inefficient)
floriank
  • 25,546
  • 9
  • 42
  • 66