Doctrine2 association mapping with conditions

后端 未结 1 1226
谎友^
谎友^ 2020-12-04 22:28

is it possible to have association mapping with conditions in Doctrine 2.4? I have entities Article and Comment. Comments needs to be approved by admin. Approval status of c

1条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-04 23:06

    You can use the Criteria API to filter the collection:

    where(Criteria::expr()->eq('approved', true));
            }
            return $this->comments->matching($criteria);
        }
    
    }
    

    This is especially nice, because Doctrine is smart enough to only go to the database if the collection hasn't already been loaded.

    0 讨论(0)
提交回复
热议问题