在模型绑定过程中,如何在cakehp3.2的控制器中给出空条件


How to give empty conditions in controller of cakephp 3.2 during model bind?

我是cakehp3的新手。下面是我的代码。

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

输出

{
        "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
        }

这里我想给出一个条件,当有一个空标志时,它不会在结果中列出。只有挂旗的岗位才会来。请推荐我。ANy suggstion将不胜感激。

有两种方法可以做到这一点:

  • 使用计数器缓存并按该字段进行筛选(flag_count>0)
  • 执行子查询以获取计数(效率低下)