, , Category.
, category.approved.
:
public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias)
{
$config = $this->getListener()->getConfiguration($this->getEntityManager(), $targetEntity->name);
if (isset($config['approvable']) && $config['approvable']) {
$column = $targetEntity->columnNames[$config['fieldName']];
return $targetTableAlias.'.'.$column.' = true';
}
}
Category ( , ).
use Doctrine\Common\Collections\ArrayCollection;
class Category {
private $products;
public function __construct()
{
$this->products = new ArrayCollection;
}
public function getProducts()
{
return $this->products;
}
}
,
$category = $this->get('doctrine')->getRepository('SomeBundle:Category')->find(5);
if( $category ) {
$products = $category->getProducts();
}
, .
:
@lracicot :
ProjectRepository, :
...
findByCategoryApproved( $product_id, $approved = true )
{
$query =
'SELECT p
FROM AcmeBundle:Product
LEFT JOIN p.categories c
WHERE p.id = :id AND c.approved = :approved';
return $this
->getEntityManager()
->createQuery( $query )
->setParameter( 'id', $product_id )
->setParameter( 'approved', $approved )
->getOneOrNullResult();
}
...
$product = $doctrine
->getRepository('AcmeBundle:Product')
->findByCategoryApproved(5);