I have the following relationships: owner => manyToOne => domain access => manyToOne => owner AND owner => oneToMany => access access => manyToOne => permission access => manyToOne => target
I'm trying to write a DQL statement that returns all owners, domains, accesses, permissions, and targets. When I iterate over my query results I get the owner and their linked domain entities, but my call to $owner->getAccesses always returns an empty ArrayCollection object. I created a pastie @ http://pastie.org/private/pfopjukmtjahvgsjz3jx0q# And just in case it gets taken down here is the raw pastie: ## storage.php [php] <?php /** * Given an owner id and an arbitrary number of ACL objects, populate the ACL objects from storage. * * @param int $owner_id * @param acl[] $acls */ public function load( $owner_id, array $acls ) { $em = $this->doctrine->get_entity_manager(); /** @var domain[] $domains */ $domains = array(); foreach( $acls as $acl ) { if( ! ($acl instanceof acl) ) { continue; } $domains[] = $acl->get_models()->get_domain()->getName(); } // // Select the models. $sql = <<<EOT select o, d, a, p, t from \\baf\\module\\acl\\model\\owner o left join o.domain d left join o.accesses a left join a.permission p left join a.target t where o.owner_id = :owner_id and d.name in ( :domain_name ) EOT; $query = $em->createQuery( $sql ); $query->setParameter( 'owner_id', $owner_id ); $query->setParameter( 'domain_name', $domains ); $query->setFetchMode( '\\baf\\module\\acl\\model\\owner', 'accesses', \Doctrine\ORM\Mapping\ClassMetadata::FETCH_EAGER ); $owners = $query->getResult(); foreach( $owners as $owner ) { /** @var owner $owner */ $domain = $owner->getDomain(); foreach( $acls as $acl ) { $models = $acl->get_models(); if( $models->get_domain()->getName() !== $domain->getName() ) { continue; } $models->set_domain( $domain ); $models->set_owner( $owner ); $models->set_accesses( $owner->getAccesses() ); $permissions = array(); $targets = array(); // // THIS IS MY PROBLEM - $owner->getAccesses() is always empty, even though access // records exist in the database. foreach( $owner->getAccesses() as $access ) { $permissions[ $access->getPermission()->getPk() ] = $access->getPermission(); $targets[ $access->getTarget()->getPk() ] = $access->getTarget(); } $models->set_permissions( array_values( $permissions ) ); $models->set_targets( array_values( $targets ) ); break; } } } ## owner.php [php] <?php /** * The database model for an 'owner' entity. */ class owner { /** * The access objects associated with this owner. * * @access protected * @var access[] */ protected $accesses; /** * The primary key. * * @access protected * @var int */ protected $pk; /** * The associated domain. * * @access protected * @var domain */ protected $domain; /** * The owner ID. * * @access protected * @var int */ protected $owner_id; /** * Creates an owner instance. * * @return owner */ public function __construct() { $this->accesses = new ArrayCollection(); } /** * Returns the access objects associated with this owner. * * @return access[] */ public function getAccesses() { return $this->accesses; } /** * Returns the primary key. * * @return int */ public function getPk() { return $this->pk; } /** * Returns the domain. * * @return domain */ public function getDomain() { return $this->domain; } /** * Sets the domain. * * @param domain $domain */ public function setDomain( domain $domain ) { $this->domain = $domain; } /** * Returns the owner ID. * * @return int */ public function getOwnerId() { return $this->owner_id; } /** * Sets the owner ID. * * @param int $owner */ public function setOwnerId( $owner ) { $this->owner_id = $owner; } } ## access.php [php] <?php /** * The database model for an 'access' entity. */ class access { /** * Returns the access attribute. * * @access protected * @var bool */ protected $access; /** * The primary key. * * @access protected * @var int */ protected $pk; /** * The associated owner. * * @access protected * @var owner */ protected $owner; /** * The associated permission. * * @access protected * @var permission */ protected $permission; /** * The associated target. * * @access protected * @var target */ protected $target; /** * Creates an access instance. * * @return access */ public function __construct() { } /** * Returns the access. * * @return bool */ public function getAccess() { return $this->access; } /** * Sets the access. * * @param bool $access */ public function setAccess( $access ) { $this->access = $access; } /** * Returns the primary key. * * @return int */ public function getPk() { return $this->pk; } /** * Returns the owner. * * @return owner */ public function getOwner() { return $this->owner; } /** * Sets the owner. * * @param owner $owner */ public function setOwner( owner $owner ) { $this->owner = $owner; } /** * Returns the permission. * * @return permission */ public function getPermission() { return $this->permission; } /** * Sets the permission. * * @param permission $permission */ public function setPermission( permission $permission ) { $this->permission = $permission; } /** * Returns the target. * * @return target */ public function getTarget() { return $this->target; } /** * Sets the target. * * @param target $target */ public function setTarget( target $target ) { $this->target = $target; } } ## access.yaml [yaml] baf\module\acl\model\access: type: entity table: baf_acl_access id: pk: type: integer generator: strategy: AUTO fields: access: type: boolean manyToOne: owner: targetEntity: baf\module\acl\model\owner inversedBy: accesses joinColumn: name: owner_fk referencedColumnName: pk cascade: [ "persist" ] permission: targetEntity: baf\module\acl\model\permission joinColumn: name: permission_fk referencedColumnName: pk cascade: [ "persist" ] target: targetEntity: baf\module\acl\model\target joinColumn: name: target_fk referencedColumnName: pk cascade: [ "persist" ] ## owner.yaml [yaml] baf\module\acl\model\owner: type: entity table: baf_acl_owner id: pk: type: integer generator: strategy: AUTO fields: owner_id: type: integer oneToMany: accesses: targetEntity: baf\module\acl\model\access mappedBy: owner manyToOne: domain: targetEntity: baf\module\acl\model\domain joinColumn: name: domain_fk referencedColumnName: pk cascade: [ "persist" ] -- You received this message because you are subscribed to the Google Groups "doctrine-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/doctrine-user. For more options, visit https://groups.google.com/d/optout.
