Doctrine2 and magic field finders do not work?

Doctrine2 allows you to query the use of magic finders based on field names. If you have an object named User , you can call $repo->findOneByUsernameAndPassword() , assuming the object has username and password fields.

How to pass parameters to magic seekers? How to query when a field that is actually a relation?

I tried:

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

and

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

but I get an error:

The User object does not have a usernameAndPassword field. Therefore, you can not call 'findOneByUsernameAndPassword'

+2
source share
1 answer

I could not find references to this syntax with Doctrine 2, although this was possible with Doctrine 1. I used it myself and remember that I have problems working. Now you prefer to do this, I think:

 $repo->findOneBy(array('username' => 'Jhon', 'password' => 'password')); 

You can find more information in this section of the Doctrine 2 documentation.

+4
source

Source: https://habr.com/ru/post/1400900/


All Articles