Search code examples
phpdoctrine-orm

What is the default for the attribute fetch in a ManyToOne annotation in Doctrine/PHP?


I have this class, using Doctrine/PHP:

class Client {
    /** @ORM\ManyToOne(targetEntity="Fee", fetch="EAGER") @ORM\JoinColumn() */
    private ?Fee $defaultFee;
    // [...]
}

If I don't specify the fetch-Attribute in the @ManyToOne-annotation, what does it default to? In this article, it says that JPA and Hibernate handle it differently already in Java, so I would like to know for sure what the default is, instead of guessing.

In the doctrine documentation I found which attributes are required and which ones are optional. But I didn't find any information about what is the default, if the optional attributes are left out.


Solution

  • The default is lazy

    Associations are marked as Lazy by default, which means the whole collection object for an association is populated the first time its accessed. If you mark an association as extra lazy the following methods on collections can be called without triggering a full load of the collection

    https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/tutorials/extra-lazy-associations.html#extra-lazy-associations