symfony - Doctrine2 eager loading runs multiple queries instead of 1 -


i'm using symfony2 doctrine2 (latest versions) , have relation defined:

/**  * @orm\onetomany(targetentity="field", mappedby="event", fetch="eager")  * @orm\orderby({"name" = "asc"})  */ protected $fields; 

the other side of relation defined as:

/**  * @orm\manytoone(targetentity="event", inversedby="fields", fetch="eager")  * @orm\joincolumn(nullable=false, ondelete="cascade")  */ protected $event; 

when doing "fetchonybyid", doctrine runs 2 queries. 1 fetch object , 1 related fields. expect join, isn't.

when done in controller, pass object twig. there retrieve fields again property of object. causes another query run retrieve fields again.

clearly i'm doing wrong, expect 1 query run , 3 run.

i believe reason occurring because you're fetching entities, not specific query. idea of doctrine you're fetching objects, not interacting database object resource if they're associated/referenced stored entities. if need query you're describing better off using dql @ point you're not fetching entities created, you're getting custom result.

i hope made sense.

basically default association you're using fetching associated objects not joined query.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -