gremo
gremo

Reputation: 48919

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

$repo->findOneByUsernameAndPassword(array('Jhon', 'password'))

but i'm getting the error:

Entity 'User' has no field 'usernameAndPassword'. You can therefore not call 'findOneByUsernameAndPassword'

Upvotes: 2

Views: 2545

Answers (1)

greg0ire
greg0ire

Reputation: 23255

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

Upvotes: 4

Related Questions