I am currently learning Symfony and Doctrine by reading the docs.
I don’t understand the difference between find and findOneById. I tried to use them both in this simple example and it looks they do the same thing to me.
$product = $this->getDoctrine()
->getRepository('AcmeStoreBundle:ProductEntity')
->findOneById($id);
Are they really the same thing or there is some difference? And where I can find the detailed documentation for all these methods?
In your case, they happen to do the same thing. Looking at this example, you’ll notice that
find()looks for the field named after the primary key.findOneBy<Field>()will explicitly use the field in the name of the method, even if it’s not the primary key, and will return the first record. So, in the end, if the primary key is indeed namedid, then both will do the same thing.