开发者

Doctrine partial objects ... is it for performance?

开发者 https://www.devze.com 2023-01-08 21:46 出处:网络
i learnt that in doctrine i can return partial objects. when i just do print_r() of the result set returned, they seem to still contain the definations for the fields, except that when i echo them out

i learnt that in doctrine i can return partial objects. when i just do print_r() of the result set returned, they seem to still contain the definations for the fields, except that when i echo them out i get nth. so i guess the definations are there but the values are not. is this for performance? eg. in SQL i sh开发者_如何学Pythonld do SELECT field1, field2 instead of SELECT *?


As far as I can tell, the ability to select just partial objects is, as you say, for performance. However, unless your table is very large, or contains columns with large sized data, I doubt there is a very large effect.

Doctrine can lazy-load the values in columns that are not selected when the object is first created. This can create performance problems, as Doctrine will perform more queries to get the missing data, so try to always make sure the data you use is selected.


I don't understand you question completely but in DQL you can do SELECT * since the ORM will always create a SELECT field1, field2,.... query out of it.

With regular SQL, you should avoid SELECTing * since it will decrease performance.


Partial queries is very useful it you want results that does not include various data such as passwords and such.

I use it for my REST API whereas I don't want to return data such as the User object's password.

Example might be:

 SELECT .... JOIN  ... partial user.{user_id, email} .... 

And then return array with Query::HYDRATE_ARRAY. Obviously it would not make that much sense if you didn't hydrate your result.

This is useful because you don't want to retrieve the users hashed password for everyone to see ( that is in a REST API where you send data to client applications such as backbone driven, or even iPhone/Android apps ) .

0

精彩评论

暂无评论...
验证码 换一张
取 消