2017 © Pedro Peláez
 

library querymap

Query mechanism for Doctrine inspired by Django's QuerySet

image

alm/querymap

Query mechanism for Doctrine inspired by Django's QuerySet

  • Sunday, July 3, 2016
  • by alumarcu
  • Repository
  • 1 Watchers
  • 0 Stars
  • 13 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Provides a simplified interface for building queries with Doctrine., (*1)

Sample usage

/** @var \QueryMap\Bundle\QueryMapBundle\Service\QueryMapFactoryService $qmFactory */
$qmFactory = $this->container->get('querymap.factory');

$qm = $qmFactory->create(Team::class, 't');

/** @var $query \Doctrine\ORM\QueryBuilder */
$query = $qm->query([
    'points__gt' => '6',
    'continent' => 'Europe'
]);

echo $query->getDQL();
//SELECT t FROM FootballBundle\Entity\Team t
//WHERE (t.points >= 6) AND (t.continent = 'Europe')

Installation

Edit your composer.json to include the package into your project, and run composer update alm/querymap, (*2)

require {
    ...
    "alm/querymap": "v1.1.*"
    ...
}

To your $bundles array in AppKernel.php include the QueryMap bundle and provide to its constructor., (*3)

$bundles = [
    ...
    new QueryMap\Bundle\QueryMapBundle\QueryMapBundle($this),
    ...
]

Next, to your config.yml file you should specify paths for your mapping yml files - if you use this feature - as such:, (*4)

query_map:
    paths:
        - '@FooBundle/Resources/querymap'
        - '@BarBundle/Resources/querymap'

For the entities you wish to filter using QueryMap, add the @QM\Map annotation in the Entity header., (*5)

use Doctrine\ORM\Mapping as ORM;
use QueryMap\Contrib\Annotation\DoctrineAnnotationMapping as QM;

/**
 * @ORM\Entity(repositoryClass=\MyBundle\Repository\TeamRepository)
 * ...
 * @QM\Map
 */

You will now be able to filter by all properties of that entity which are defined as @ORM\Column, @ORM\ManyToOne or @ORM\OneToOne., (*6)

The Versions