在Doctrine中按对象查找:FindBy(Object)


Finding by Object in Doctrine : FindBy( Object )

是否可以在findBy函数等函数中传递对象来检索数据?

注意:** $resto对象没有填写**id属性。因此,学说必须找到最接近的匹配条目。

例如:

       $resto = new Restaurant();
       $resto->setName('...')
       ...

       $repository = $this->getDoctrine()->getRepository('LesDataBundle:Restaurants');
       $result =  $repository->findBy($resto);

不可以,但是可以使用自定义表达式

$repository->findBy([
    'some_field' => $resto->getSomeField(),
    'other_field' => $resto->getOtherField()
]);