Magic Doctrine2 finders when field has underscore?

前端 未结 1 796
忘了有多久
忘了有多久 2021-01-13 09:01

I\'m having problems using find*() magic methods of Doctrine2 when the field has an underscore in between.

$repository->find         


        
1条回答
  •  迷失自我
    2021-01-13 09:48

    I recall having had the same problem and think I solved it by writing something like this :

    $repository->findBy(array('is_enabled' => true));

    Let's look at the code :

    _class->hasField($fieldName) || $this->_class->hasAssociation($fieldName)) {
            return $this->$method(array($fieldName => $arguments[0]));
        } else {
            throw ORMException::invalidFindByCall($this->_entityName, $fieldName, $method.$by);
        }
    }
    

    The key line is here:

    $fieldName = lcfirst(\Doctrine\Common\Util\Inflector::classify($by));
    

    Now let's have a look to classify :

    It looks like you're supposed to write your fields "likeThis" if you want this to work.

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