开发者

Doctrine2 and magic finders with more fields not working?

开发者 https://www.devze.com 2023-04-11 21:13 出处:网络
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 u

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号