[FLOW3-general] Question how-to select entities (owning side) that have an Many-To-Many Association, filtered by some entities of the inverse side

mosaiq_marcel mosaiq_marcel at web.de
Thu Apr 26 18:42:31 CEST 2012


Hi,

im using FLOW3 1.0.4 and have some trouble to get an result if i want to 
get facilities that have one or more associated filters. Here are the 
involved Classes:

/**
  * A Facility
  *
  * @FLOW3\Scope("prototype")
  * @FLOW3\Entity
  */
class Facility {
     /**
      * The full_name
      *
      * @var string
      * @FLOW3\Validate(type="Text")
      * @FLOW3\Validate(type="NotEmpty")
      * @FLOW3\Validate(type="StringLength", options={"maximum"=100 })
      * @ORM\Column(length=100)
      */
     protected $full_name;

     /**
      * The filter
      *
      * @var 
\Doctrine\Common\Collections\Collection<\Mfg\Maps\Domain\Model\Filter>
      * @FLOW3\Validate(type="NotEmpty")
      * @ORM\ManyToMany(inversedBy="facility", cascade={"persist"})
      */
     protected $filter;

     // ... some additional code

}

/**
  * A Filter
  *
  * @FLOW3\Scope("prototype")
  * @FLOW3\Entity
  */
class Filter {
     /**
      * The name
      *
      * @var string
      * @FLOW3\Validate(type="Text")
      * @FLOW3\Validate(type="NotEmpty")
      * @FLOW3\Validate(type="StringLength", options={"maximum"=100 })
      * @ORM\Column(length=100)
      */
     protected $name;

     /**
      * The facility
      *
      * @var 
\Doctrine\Common\Collections\Collection<\Mfg\Maps\Domain\Model\Facility>
      * @ORM\ManyToMany(mappedBy="filter")
      */
     protected $facility;

     //... some additional code

}

/**
  * A repository for Facilities
  *
  * @FLOW3\Scope("singleton")
  */
class FacilityRepository extends \TYPO3\FLOW3\Persistence\Repository {
     public function findFacilityByFilter($filterIdentity) {
         // Does not work because i think 'filter' is unknown at this time
         $query = $this->createQuery();
         return $query->matching( $query->in('filter', $filterIdentity) 
)->execute();

         // Try to use DQL - does not work because 'entityManager' is an 
undefined property
         $query = $this->entityManager->createQuery('???');
         return $query->execute();
     }
}

The given $filterIdentity is an array of identity numbers like
array(
     '1a791d01-12b6-4dfe-bdfe-cb9d439168c1',    // Filter 01
     'd0dfddc3-909e-4aed-89fa-a33f3db3e08f'      // Filter 02
)

My basic question now is, how to find all facilities which has a set of 
specified filters assosiated and how can i get access to the 
entityManager to use plain doctrine (queryBuilder or DQL)?

Hope, someone can help me or can give me some food for thought before i 
loose all my hair :-)

Greetings,
Marcel



More information about the FLOW3-general mailing list