开发者

ORM Assign data to view

Working on an MVC application with Doctrine as our ORM. Currently we're looking at improving the way we use object relations within our application, a开发者_如何学运维nd a question came up:

Should we directly assign a doctrine entity to the view or just an array of data?

Each has it's own advantages and disadvantages. For example, setting an entity gives our frontend devs the ability to query our database, which shouldn't be done it the view and could be used unwisely. On the other hand, assigning an array of data means we have to first query everything they could possibly want and fetch as array. Array access also doesn't give them autocompletion.

Which do you think is our best option going forward with the least amount of potential complications?

Thanks for your time.


I think the answer is mostly about the efficiency/speed at which your app needs to operate. If by "frontend devs" you mean HTML/CSS devs, then they probably won't understand what kinds of queries looping the wrong thing (e.g. $object->getRelatedObject()) can create in the background. Something that could be performed with a single tight query returning array data may end up generating 10-15 queries that hydrate full objects and slow down the application noticeably.

If I had to generalize, I'd say that if you're building a small app where scaling up isn't a major concern, it doesn't really matter because you won't notice the speed hit and your devs have more leeway to do nasty things. Otherwise, I'd go for array data.

Hope that helps.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜