symfony - Symfony2 Doctrine association result -
i new symfony/doctrine. created 2 entities managing comments , documents attached them: here comment entity, , here comment document entity. question when fetch data db this:
$comment = $em->getrepository('pathtobundle:comment')->findoneby( array('ordernumber' => '123456') ); and, let's wan't debug
print_r($comment); it print's out this:
path\tobundle\entity\comment object ( [id:path\tobundle\entity\comment:private] => 1 [ordernumber:path\tobundle\entity\comment:private] => 123456 [category:path\tobundle\entity\comment:private] => cat1 [comment:path\tobundle\entity\comment:private] => com1 [user:path\tobundle\entity\comment:private] => usr1 [version:path\tobundle\entity\comment:private] => 0 [documents:path\tobundle\entity\comment:private] => doctrine\orm\persistentcollection object ( [snapshot:doctrine\orm\persistentcollection:private] => array ( ) [owner:doctrine\orm\persistentcollection:private] => path\tobundle\entity\comment object *recursion* [association:doctrine\orm\persistentcollection:private] => array ( [fieldname] => documents [mappedby] => comment [targetentity] => path\tobundle\entity\commentdocument [cascade] => array ( ) [orphanremoval] => [fetch] => 2 [type] => 4 [inversedby] => [isowningside] => [sourceentity] => path\tobundle\entity\comment [iscascaderemove] => [iscascadepersist] => [iscascaderefresh] => [iscascademerge] => [iscascadedetach] => ) and it's beginning, goes on , on until browser crashes. if try access single property
print_r($input->getcomment()); it works ok.
so behavior normal, or done wrong? , how can access associated documents table values?
it's normal. note first print_r attempt on doctrine object , second 1 on string. doctrine objects many levels deep , contain lot of information. instead of using print_r try using doctrine's debug class, lets specify maximum depth.
http://www.doctrine-project.org/api/common/2.4/class-doctrine.common.util.debug.html
\doctrine\common\util\debug::dump($comment, $maxdepth) if entities setup correctly, should able access associated documents by
$comments->getdocuments();
Comments
Post a Comment