Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
360 views
in Technique[技术] by (71.8m points)

php - How can public fields "break lazy loading" in Doctrine 2?

When I run doctrine orm:validate-schema, it pops up a bunch of warnings about my mapped columns being public and not using getter/setter methods to wrap them. It says that they "break lazy loading". I can understand how making associated collections public could be problematic (I do make these private and wrap them), but how is this an issue for fields on the object? Fields are loaded in full, to my knowledge.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I'll give a shot at this although I'm certainly not a Doctrine2 expert.

From my (limited) usage and testing it seems Doctrine may give you a related object without loading the data for that object. At that point public properties will break lazy loading.

Doctrine is lazy loading at the point where the persisted data is requested, not when the object that contains persisted data is requested.

Update: I took a look at the actual proxy code and it seems my original understanding was mostly correct. The proxy object doesn't load itself until a method of the object is called. So any request to a public property would not load the data.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...