Doctrine 2 Lazy loading fail

I have two objects: user and client, one client can have many users.

Often I want to have a custom object and lazy client loading, but for some reason the client proxy does not load when I try to access its properties.

If I discard data like this \Doctrine\Common\Utils\Debug::log($user->client);, it will output a client proxy with its client id.

If I change the selection policy to "EAGER", I will get the client object unchanged, but I do not always need the client object when accessing users, so I prefer to use LAZY if possible.

EDIT

When I do this later:

$user->client->name

I will come back even if my proxy received a client ID.

These are my two relationships (inside the annotation):

// user annotation

/**
 * @var Entities\Client
 *
 * @ManyToOne(targetEntity="Client", inversedBy="users", fetch="LAZY")
 */
private $client;

// client annotation

/**
 * @var Entities\User
 *
 * @OneToMany(targetEntity="User", mappedBy="client", cascade={"all"}, fetch="LAZY")
 */
private $users;

EDIT

, , , , -.

+5
1

, . , . , Doctrine -, "" ( , ).

( $user->client->name), Doctrine .

+6

All Articles