Doctrine2 and magic finders with more fields not working?
Doctrine2 allows you to query using magic finders based on field names. If you have an entity named User
you should able to call $repo->findOneByUsernameAndPassword()
assuming that the entity has username and password fields.
How can i pass parameters to magic finders? How to query when the field that is actually a relation?
I've tried:
$repo->findOneByUsernameAndPassword('Jhon', 'password')
and
$开发者_JAVA百科repo->findOneByUsernameAndPassword(array('Jhon', 'password'))
but i'm getting the error:
Entity 'User' has no field 'usernameAndPassword'. You can therefore not call 'findOneByUsernameAndPassword'
I couldn't find any reference for this syntax with Doctrine 2, though it was possible with Doctrine 1. I used it myself then and remember having problems getting it to work. Now you would rather do this I guess :
$repo->findOneBy(array('username' => 'Jhon', 'password' => 'password'));
You can get more information in this § of the Doctrine 2 documentation
精彩评论