Skip to content

Eager Fetch Type On Association (ARCH7060)

Key php.orm.eager-fetch-type-on-association · Severity warning · Category orm

Declaring a relation fetch="EAGER" at the mapping level loads it on every query of the owning entity, even when unneeded. The fetch strategy should default to lazy, with eager chosen per query.

<?php
class Order
{
#[ORM\OneToMany(targetEntity: LineItem::class, fetch: 'EAGER')]
private Collection $lineItems; // loaded on every Order query
}
<?php
class Order
{
#[ORM\OneToMany(targetEntity: LineItem::class, fetch: 'LAZY')]
private Collection $lineItems; // eager only when needed: ->with('lineItems')
}

Keep relations lazy in the mapping; opt into eager loading on the query that needs it.