Doctrine 2 findAll returns just 1 result - php

The findAll() finds one result in my repository:
$retorno[] = $bd->getEntityManager()->getRepository($classname)->findAll();
Class of entity:
<?php
use Doctrine\ORM\Mapping as ORM;
/**
* Subtipo
*
* #ORM\Table(name="subtipo", indexes={#ORM\Index(name="fk_Subtipo_Tipo1_idx", columns={"Tipo_id"})})
* #ORM\Entity
*/
class Subtipo
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="nome", type="string", length=45, nullable=false)
*/
private $nome;
/**
* #var \Tipo
*
* #ORM\ManyToOne(targetEntity="Tipo")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="Tipo_id", referencedColumnName="id")
* })
*/
private $tipo;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set nome
*
* #param string $nome
*
* #return Subtipo
*/
public function setNome($nome)
{
$this->nome = $nome;
return $this;
}
/**
* Get nome
*
* #return string
*/
public function getNome()
{
return $this->nome;
}
/**
* Set tipo
*
* #param \Tipo $tipo
*
* #return Subtipo
*/
public function setTipo(\Tipo $tipo = null)
{
$this->tipo = $tipo;
return $this;
}
/**
* Get tipo
*
* #return \Tipo
*/
public function getTipo()
{
return $this->tipo;
}
}
Somebody can help?

If you do this
$retorno[] = $bd->getEntityManager()->getRepository($classname)->findAll();
^----- this
You're creating an array of arrays (or array of ArrayCollection) so, if you inspect length of $retorno[] this will result in 1 element that will contain real results.
Something like
$retorno = [
0 => [
0 => 'first real result',
1 => 'second real result',
[...]
n => 'nth real result'
]
];
Just use this syntax
$retorno = $bd->getEntityManager()->getRepository($classname)->findAll();

Related

The option "filters" does not have a callable "setFilters" ("setfilters") setter method

Environment:
"require": {
"php": "5.6",
"zendframework/zendframework": "2.5.0",
"zendframework/zend-servicemanager": "2.5.1",
"zendframework/zend-developer-tools": "1.0.0",
"doctrine/doctrine-orm-module": "0.9.2",
"acelaya/zf2-acmailer": "4.*",
"tasmaniski/zend-params-helper": "^1.0"
}
Fatal error: Uncaught exception 'Zend\Stdlib\Exception\BadMethodCallException' with message 'The option "filters" does not have a callable "setFilters" ("setfilters") setter method which must be defined' in C:\OSPanel\domains\csmCrew_github\vendor\zendframework\zend-servicemanager\src\ServiceManager.php on line 1135
I am trying to add SQL filter using this DareDevels tutorial
my interface: VacanciesFilterInterface.php
namespace Common\DoctrineFilter;
Interface VacanciesFilterInterface
{
public function setFilters($filters);
}
my filter class: VacanciesFilter.php
namespace Common\DoctrineFilter;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Query\Filter\SQLFilter;
class VacanciesFilter extends SQLFilter
{
/**
* Gets the SQL query part to add to a query.
*
* #param ClassMetaData $targetEntity
* #param string $targetTableAlias
*
* #return string The constraint SQL if there is available, empty string otherwise.
*/
public function addFilterConstraint (ClassMetadata $targetEntity, $targetTableAlias)
{
// Check if the entity implements the LocalAware interface
if (!$targetEntity->reflClass->implementsInterface('\Common\DoctrineFilter\VacanciesFilterInterface')) {
return '';
}
return $targetTableAlias.'.Vacancies = ' . $this->getParameter('Vacancies'); // getParameter applies quoting automatically
}
my module.config.php:
'doctrine' => array(
'driver' => array(
// defines an annotation driver with two paths, and names it `my_annotation_driver`
'common_entity' => array(
'class' => \Doctrine\ORM\Mapping\Driver\AnnotationDriver::class,
'cache' => 'array',
'paths' => array(
__DIR__ . '/../src/Common/Entity',
__DIR__ . '/../src/Common/Entity/Repository',
),
),
// default metadata driver, aggregates all other drivers into a single one.
// Override `orm_default` only if you know what you're doing
'orm_default' => array(
'drivers' => array(
// register `my_annotation_driver` for any entity under namespace `My\Namespace`
'Common\Entity' => 'common_entity',
),
'filters' => array(
'vacancies' => 'Common\DoctrineFilter\VacanciesFilter',
),
),
),
),
I add filter in my controller using these methods:
public function enableVacanciesFilter()
{
$em = $this->getEntityManager();
$filter = $em->getFilters()->enable('vacancies');
$filter->setParameter('vacancies', '41');
}
/**
* Disable locale filter
*/
public function disableVacanciesFilter()
{
$em = $this->getEntityManager();
$filter = $em->getFilters()->disable('vacancies');
}
So the question is: how can I implement that callable setFilters setter method ?
I have tried to implement Interface in my Entity:
<?php
namespace Common\Entity;
use Common\DoctrineFilter\VacanciesFilterInterface;
use Doctrine\ORM\Mapping as ORM;
/**
* Vacancies
*
* #ORM\Table(name="vacancies", indexes={#ORM\Index(name="RankId_fk", columns={"rank_id"}), #ORM\Index(name="id", columns={"id"}), #ORM\Index(name="FK_vacancies_crewing_companies", columns={"company_id"}), #ORM\Index(name="FK_vacancies_vessels", columns={"vessel_id"}), #ORM\Index(name="FK_vacancies_vacancy_positions", columns={"position"}), #ORM\Index(name="status_id", columns={"status_id"})})
* #ORM\Entity
*/
class Vacancies implements VacanciesFilterInterface
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="title", type="string", length=128, nullable=false)
*/
private $title = '';
/**
* #var string
*
* #ORM\Column(name="additional_info", type="string", length=255, nullable=false)
*/
private $additionalInfo = '';
/**
* #var integer
*
* #ORM\Column(name="duration_of_contract_in_months", type="smallint", nullable=false)
*/
private $durationOfContractInMonths;
/**
* #var \DateTime
*
* #ORM\Column(name="joining_date", type="date", nullable=false)
*/
private $joiningDate;
/**
* #var integer
*
* #ORM\Column(name="salary_per_month", type="integer", nullable=false)
*/
private $salaryPerMonth;
/**
* #var boolean
*
* #ORM\Column(name="required_age_from", type="boolean", nullable=false)
*/
private $requiredAgeFrom;
/**
* #var boolean
*
* #ORM\Column(name="required_age_to", type="boolean", nullable=false)
*/
private $requiredAgeTo;
/**
* #var \DateTime
*
* #ORM\Column(name="creation_date", type="datetime", nullable=false)
*/
private $creationDate;
/**
* #var integer
*
* #ORM\Column(name="views_count", type="integer", nullable=true)
*/
private $viewsCount = '0';
/**
* #var integer
*
* #ORM\Column(name="job_seekers_applied", type="integer", nullable=true)
*/
private $jobSeekersApplied = '0';
/**
* #var boolean
*
* #ORM\Column(name="is_published", type="boolean", nullable=false)
*/
private $isPublished = '0';
/**
* #var \Common\Entity\CrewingCompanies
*
* #ORM\ManyToOne(targetEntity="Common\Entity\CrewingCompanies")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="company_id", referencedColumnName="id")
* })
*/
private $company;
/**
* #var \Common\Entity\VacancyPositions
*
* #ORM\ManyToOne(targetEntity="Common\Entity\VacancyPositions")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="position", referencedColumnName="id")
* })
*/
private $position;
/**
* #var \Common\Entity\Vessels
*
* #ORM\ManyToOne(targetEntity="Common\Entity\Vessels")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="vessel_id", referencedColumnName="id")
* })
*/
private $vessel;
/**
* #var \Common\Entity\Ranks
*
* #ORM\ManyToOne(targetEntity="Common\Entity\Ranks")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="rank_id", referencedColumnName="id")
* })
*/
private $rank;
/**
* #var \Common\Entity\VacancyStatuses
*
* #ORM\ManyToOne(targetEntity="Common\Entity\VacancyStatuses")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="status_id", referencedColumnName="id")
* })
*/
private $status;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set title
*
* #param string $title
*
* #return Vacancies
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* #return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set additionalInfo
*
* #param string $additionalInfo
*
* #return Vacancies
*/
public function setAdditionalInfo($additionalInfo)
{
$this->additionalInfo = $additionalInfo;
return $this;
}
/**
* Get additionalInfo
*
* #return string
*/
public function getAdditionalInfo()
{
return $this->additionalInfo;
}
/**
* Set durationOfContractInMonths
*
* #param integer $durationOfContractInMonths
*
* #return Vacancies
*/
public function setDurationOfContractInMonths($durationOfContractInMonths)
{
$this->durationOfContractInMonths = $durationOfContractInMonths;
return $this;
}
/**
* Get durationOfContractInMonths
*
* #return integer
*/
public function getDurationOfContractInMonths()
{
return $this->durationOfContractInMonths;
}
/**
* Set joiningDate
*
* #param \DateTime $joiningDate
*
* #return Vacancies
*/
public function setJoiningDate($joiningDate)
{
$this->joiningDate = $joiningDate;
return $this;
}
/**
* Get joiningDate
*
* #return \DateTime
*/
public function getJoiningDate()
{
return $this->joiningDate;
}
/**
* Set salaryPerMonth
*
* #param integer $salaryPerMonth
*
* #return Vacancies
*/
public function setSalaryPerMonth($salaryPerMonth)
{
$this->salaryPerMonth = $salaryPerMonth;
return $this;
}
/**
* Get salaryPerMonth
*
* #return integer
*/
public function getSalaryPerMonth()
{
return $this->salaryPerMonth;
}
/**
* Set requiredAgeFrom
*
* #param boolean $requiredAgeFrom
*
* #return Vacancies
*/
public function setRequiredAgeFrom($requiredAgeFrom)
{
$this->requiredAgeFrom = $requiredAgeFrom;
return $this;
}
/**
* Get requiredAgeFrom
*
* #return boolean
*/
public function getRequiredAgeFrom()
{
return $this->requiredAgeFrom;
}
/**
* Set requiredAgeTo
*
* #param boolean $requiredAgeTo
*
* #return Vacancies
*/
public function setRequiredAgeTo($requiredAgeTo)
{
$this->requiredAgeTo = $requiredAgeTo;
return $this;
}
/**
* Get requiredAgeTo
*
* #return boolean
*/
public function getRequiredAgeTo()
{
return $this->requiredAgeTo;
}
/**
* Set creationDate
*
* #param \DateTime $creationDate
*
* #return Vacancies
*/
public function setCreationDate($creationDate)
{
$this->creationDate = $creationDate;
return $this;
}
/**
* Get creationDate
*
* #return \DateTime
*/
public function getCreationDate()
{
return $this->creationDate;
}
/**
* Set viewsCount
*
* #param integer $viewsCount
*
* #return Vacancies
*/
public function setViewsCount($viewsCount)
{
$this->viewsCount = $viewsCount;
return $this;
}
/**
* Get viewsCount
*
* #return integer
*/
public function getViewsCount()
{
return $this->viewsCount;
}
/**
* Set jobSeekersApplied
*
* #param integer $jobSeekersApplied
*
* #return Vacancies
*/
public function setJobSeekersApplied($jobSeekersApplied)
{
$this->jobSeekersApplied = $jobSeekersApplied;
return $this;
}
/**
* Get jobSeekersApplied
*
* #return integer
*/
public function getJobSeekersApplied()
{
return $this->jobSeekersApplied;
}
/**
* Set isPublished
*
* #param boolean $isPublished
*
* #return Vacancies
*/
public function setIsPublished($isPublished)
{
$this->isPublished = $isPublished;
return $this;
}
/**
* Get isPublished
*
* #return boolean
*/
public function getIsPublished()
{
return $this->isPublished;
}
/**
* Set company
*
* #param \Common\Entity\CrewingCompanies $company
*
* #return Vacancies
*/
public function setCompany(\Common\Entity\CrewingCompanies $company = null)
{
$this->company = $company;
return $this;
}
/**
* Get company
*
* #return \Common\Entity\CrewingCompanies
*/
public function getCompany()
{
return $this->company;
}
/**
* Set position
*
* #param \Common\Entity\VacancyPositions $position
*
* #return Vacancies
*/
public function setPosition(\Common\Entity\VacancyPositions $position = null)
{
$this->position = $position;
return $this;
}
/**
* Get position
*
* #return \Common\Entity\VacancyPositions
*/
public function getPosition()
{
return $this->position;
}
/**
* Set vessel
*
* #param \Common\Entity\Vessels $vessel
*
* #return Vacancies
*/
public function setVessel(\Common\Entity\Vessels $vessel = null)
{
$this->vessel = $vessel;
return $this;
}
/**
* Get vessel
*
* #return \Common\Entity\Vessels
*/
public function getVessel()
{
return $this->vessel;
}
/**
* Set rank
*
* #param \Common\Entity\Ranks $rank
*
* #return Vacancies
*/
public function setRank(\Common\Entity\Ranks $rank = null)
{
$this->rank = $rank;
return $this;
}
/**
* Get rank
*
* #return \Common\Entity\Ranks
*/
public function getRank()
{
return $this->rank;
}
/**
* Set status
*
* #param \Common\Entity\VacancyStatuses $status
*
* #return Vacancies
*/
public function setStatus(\Common\Entity\VacancyStatuses $status = null)
{
$this->status = $status;
return $this;
}
/**
* Get status
*
* #return \Common\Entity\VacancyStatuses
*/
public function getStatus()
{
return $this->status;
}
public function setFilters ($filters)
{
$this->filters = $filters;
// TODO: Implement setFilters() method.
}
}
But nothing helps to deal with that error.

Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN'

I am building a shipping system for an eCommerce site using doctrine. To do this I have get the appropriate shipping methods and prices based on product and region data in the checkout.
I am using the following code with the QueryBuilder:
$shippingPriceReccords
= $this->em->createQueryBuilder()
->select('price')
->from('OrderShippingPrice', 'price')
->innerJoin('OrderShippingMethod', 'method', 'price.fkOrderShippingMethod = method.id')
->innerJoin('OrderShippingMethodRegionMapping', 'map', 'map.fkOrderShippingMethod = method.id')
->where('price.fkProductType = :fkProductType')
->andwhere('price.fkBrand = :fkBrand')
->andwhere('map.fkRegion = :fkRegion')
->setParameters([
'fkProductType' => $fkProductType,
'fkBrand' => $fkBrand,
'fkRegion' => $regionID,
])
->getQuery()
->setFetchMode("OrderCart", "address", \Doctrine\ORM\Mapping\ClassMetadata::FETCH_EAGER)
->getResult();
But this is failing and giving me this error:
[Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN'
The DQL from the above query:
SELECT price FROM OrderShippingPrice price INNER JOIN OrderShippingMethod method INNER JOIN OrderShippingMethodRegionMapping map WHERE price.fkProductType = :fkProductType AND price.fkBrand = :fkBrand AND map.fkRegion = :fkRegion
OrderShippingPrice contains:
<?php
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
/**
* OrderShippingPrice
*
* #ORM\Table(name="orderShippingPrice")
* #ORM\Entity
*/
class OrderShippingPrice
{
/**
*
* Normal string / int object data
*
*/
/**
* #var int
*
* #ORM\Column(name="id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var int
*
* #ORM\Column(name="fkOrderShippingMethod", type="integer", nullable=true)
*/
private $fkOrderShippingMethod = '0';
/**
* #var float
*
* #ORM\Column(name="price", type="float", precision=7, scale=2, nullable=false)
*/
private $price = '0.00';
/**
* #var int
*
* #ORM\Column(name="fkProductType", type="integer", nullable=true)
*/
private $fkProductType = '0';
/**
* #var int
*
* #ORM\Column(name="fkBrand", type="integer", nullable=true)
*/
private $fkBrand = '0';
/**
* #var string
*
* #ORM\Column(name="isExpeditable", type="string", length=16, nullable=false)
*/
private $isExpeditable = '0';
/**
* #var string
*
* #ORM\Column(name="expediteDescription", type="text", length=65535, nullable=false)
*/
private $expediteDescription = '';
/**
* #var string
*
* #ORM\Column(name="showLiftGateOption", type="string", length=16, nullable=false)
*/
private $showLiftGateOption = '0';
/**
* #var string
*
* #ORM\Column(name="showDestinationOption", type="string", length=16, nullable=false)
*/
private $showDestinationOption = '0';
/**
* #var string
*
* #ORM\Column(name="productNotAvailable", type="string", length=16, nullable=false)
*/
private $productNotAvailable = '0';
/**
*
* Relationship managment propperties
*
*/
/**
* Many OrderShippingPrices have One OrderShippingMethod.
* #ORM\ManyToOne(targetEntity="OrderShippingMethod", fetch="EAGER")
* #ORM\JoinColumn(name="fkOrderShippingMethod", referencedColumnName="id")
**/
private $orderShippingMethod;
/**
* Get orderOrderShippingMethod
*
* #return OrderShippingMethod
*/
public function getOrderShippingMethod()
{
return $this->orderShippingMethod;
}
/**
*
* Normal string / int getters and setters
*
*/
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set fkOrderShippingMethod
*
* #param string $fkOrderShippingMethod
*
* #return OrderCart
*/
public function setFkOrderShippingMethod($fkOrderShippingMethod)
{
$this->fkOrderShippingMethod = $fkOrderShippingMethod;
return $this;
}
/**
* Get fkOrderShippingMethod
*
* #return string
*/
public function getFkOrderShippingMethod()
{
return $this->fkOrderShippingMethod;
}
/**
* Set price
*
* #param string $price
*
* #return OrderCart
*/
public function setPrice($price)
{
$this->price = $price;
return $this;
}
/**
* Get price
*
* #return string
*/
public function getPrice()
{
return $this->price;
}
/**
* Set fkProductType
*
* #param string $fkProductType
*
* #return OrderCart
*/
public function setFkProductType($fkProductType)
{
$this->fkProductType = $fkProductType;
return $this;
}
/**
* Get fkProductType
*
* #return string
*/
public function getFkProductType()
{
return $this->fkProductType;
}
/**
* Set fkBrand
*
* #param string $fkBrand
*
* #return OrderCart
*/
public function setFkBrand($fkBrand)
{
$this->fkBrand = $fkBrand;
return $this;
}
/**
* Get fkBrand
*
* #return string
*/
public function getFkBrand()
{
return $this->fkBrand;
}
/**
* Set isExpeditable
*
* #param string $isExpeditable
*
* #return OrderCart
*/
public function setIsExpeditable($isExpeditable)
{
$this->isExpeditable = $isExpeditable;
return $this;
}
/**
* Get isExpeditable
*
* #return string
*/
public function getIsExpeditable()
{
return $this->isExpeditable;
}
/**
* Set expediteDescription
*
* #param string $expediteDescription
*
* #return OrderCart
*/
public function setExpediteDescription($expediteDescription)
{
$this->expediteDescription = $expediteDescription;
return $this;
}
/**
* Get expediteDescription
*
* #return string
*/
public function getExpediteDescription()
{
return $this->expediteDescription;
}
/**
* Set showLiftGateOption
*
* #param string $showLiftGateOption
*
* #return OrderCart
*/
public function setShowLiftGateOption($showLiftGateOption)
{
$this->showLiftGateOption = $showLiftGateOption;
return $this;
}
/**
* Get showLiftGateOption
*
* #return string
*/
public function getShowLiftGateOption()
{
return $this->showLiftGateOption;
}
/**
* Set showDestinationOption
*
* #param string $showDestinationOption
*
* #return OrderCart
*/
public function setShowDestinationOption($showDestinationOption)
{
$this->showDestinationOption = $showDestinationOption;
return $this;
}
/**
* Get showDestinationOption
*
* #return string
*/
public function getShowDestinationOption()
{
return $this->showDestinationOption;
}
/**
* Set productNotAvailable
*
* #param string $productNotAvailable
*
* #return OrderCart
*/
public function setProductNotAvailable($productNotAvailable)
{
$this->productNotAvailable = $productNotAvailable;
return $this;
}
/**
* Get productNotAvailable
*
* #return string
*/
public function getProductNotAvailable()
{
return $this->productNotAvailable;
}
}
OrderShippingMethod contains:
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
/**
* OrderShippingMethod
*
* #ORM\Table(name="orderShippingMethod")
* #ORM\Entity
*/
class OrderShippingMethod
{
/**
*
* Normal string / int object data
*
*/
/**
* #var int
*
* #ORM\Column(name="id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="name", type="text", length=255, nullable=false)
*/
private $name = '';
/**
* #var string
*
* #ORM\Column(name="carrier", type="string", length=32, nullable=false)
*/
private $carrier = '';
/**
* #var string
*
* #ORM\Column(name="bvCode", type="string", length=32, nullable=false)
*/
private $bvCode = '';
/**
* #var string
*
* #ORM\Column(name="trackingUrl", type="string", length=255, nullable=true)
*/
private $trackingUrl = '';
/**
* #var int
*
* #ORM\Column(name="minimumLeadTime", type="integer", nullable=false)
*/
private $minimumLeadTime = '0';
/**
* #var int
*
* #ORM\Column(name="maximumLeadTime", type="integer", nullable=false)
*/
private $maximumLeadTime = '0';
/**
*
* Relationship managment propperties
*
*/
/**
* #ORM\OneToMany(targetEntity="OrderShippingMethodRegionMapping", mappedBy="orderShippingMethod", cascade={"persist", "remove"}, orphanRemoval=true, fetch="EAGER")
* #var orderShippingMethodRegionMappings[]
**/
public $orderShippingMethodRegionMappings;
/**
* Constructor
*
* Create array for collection of orderShippingMethodRegionMappings
*/
public function __construct()
{
$this->orderShippingMethodRegionMappings = new ArrayCollection();
}
/**
* Get orderShippingMethodRegionMapping(s)
*
* #return array
*/
public function getOrderShippingMethodRegionMappings()
{
return $this->orderShippingMethodRegionMappings;
}
/**
*
* Normal string / int getters and setters
*
*/
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* #param int $name
*
* #return OrderCart
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* #return int
*/
public function getName()
{
return $this->name;
}
/**
* Set carrier
*
* #param string $carrier
*
* #return OrderCart
*/
public function setCarrier($carrier)
{
$this->carrier = $carrier;
return $this;
}
/**
* Get carrier
*
* #return string
*/
public function getCarrier()
{
return $this->carrier;
}
/**
* Set bvCode
*
* #param string $bvCode
*
* #return OrderCart
*/
public function setBvCode($bvCode)
{
$this->bvCode = $bvCode;
return $this;
}
/**
* Get bvCode
*
* #return string
*/
public function getBvCode()
{
return $this->bvCode;
}
/**
* Set trackingUrl
*
* #param string $trackingUrl
*
* #return OrderCart
*/
public function setTrackingUrl($trackingUrl)
{
$this->trackingUrl = $trackingUrl;
return $this;
}
/**
* Get trackingUrl
*
* #return string
*/
public function getTrackingUrl()
{
return $this->trackingUrl;
}
/**
* Set minimumLeadTime
*
* #param string $minimumLeadTime
*
* #return OrderCart
*/
public function setMinimumLeadTime($minimumLeadTime)
{
$this->minimumLeadTime = $minimumLeadTime;
return $this;
}
/**
* Get minimumLeadTime
*
* #return string
*/
public function getMinimumLeadTime()
{
return $this->minimumLeadTime;
}
/**
* Set maximumLeadTime
*
* #param string $maximumLeadTime
*
* #return OrderCart
*/
public function setMaximumLeadTime($maximumLeadTime)
{
$this->maximumLeadTime = $maximumLeadTime;
return $this;
}
/**
* Get maximumLeadTime
*
* #return string
*/
public function getMaximumLeadTime()
{
return $this->maximumLeadTime;
}
}
OrderShippingMethodRegionMapping contains:
<?php
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
/**
* OrderShippingMethodRegionMapping
*
* #ORM\Table(name="orderShippingMethodRegionMapping")
* #ORM\Entity
*/
class OrderShippingMethodRegionMapping
{
/**
*
* Normal string / int object data
*
*/
/**
* #var int
*
* #ORM\Column(name="id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var int
*
* #ORM\Column(name="fkOrderShippingMethod", type="integer")
*/
private $fkOrderShippingMethod = '0';
/**
* #var int
*
* #ORM\Column(name="fkOrderRegion", type="integer")
*/
private $fkOrderRegion = '0';
/**
*
* Relationship managment propperties
*
*/
/**
* Many OrderShippingPrices have One OrderShippingMethod.
* #ORM\ManyToOne(targetEntity="OrderShippingMethod", inversedBy="orderShippingMethodRegionMappings")
* #ORM\JoinColumn(name="fkOrderShippingMethod", referencedColumnName="id")
**/
private $orderShippingMethod;
/**
* Sets a new OrderShippingMethod and cleans the previous one if set
* #param OrderShippingMethod
*/
public function setOrderShippingMethod(OrderShippingMethod $orderShippingMethod)
{
$this->orderShippingMethod = $orderShippingMethod;
}
/**
* Get orderOrderShippingMethod
*
* #return OrderShippingMethod
*/
public function getOrderShippingMethod()
{
return $this->orderShippingMethod;
}
/**
*
* Normal string / int getters and setters
*
*/
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set fkOrderShippingMethod
*
* #param int $fkOrderShippingMethod
*
* #return OrderCart
*/
public function setFkOrderShippingMethod($fkOrderShippingMethod)
{
$this->fkOrderShippingMethod = $fkOrderShippingMethod;
return $this;
}
/**
* Get fkOrderShippingMethod
*
* #return int
*/
public function getFkOrderShippingMethod()
{
return $this->fkOrderShippingMethod;
}
/**
* Set fkOrderRegion
*
* #param int $fkOrderRegion
*
* #return OrderCart
*/
public function setFkOrderRegion($fkOrderRegion)
{
$this->fkOrderRegion = $fkOrderRegion;
return $this;
}
/**
* Get fkOrderRegion
*
* #return int
*/
public function getFkOrderRegion()
{
return $this->fkOrderRegion;
}
}
Can someone tell me what I am doing wrong? Thanks for the help.
You are missing an argument in the innerJoin method call. You have to do this :
$shippingPriceReccords
= $this->em->createQueryBuilder()
->select('price')
->from('OrderShippingPrice', 'price')
->innerJoin('OrderShippingMethod', 'method', 'WITH', 'price.fkOrderShippingMethod = method.id')
->innerJoin('OrderShippingMethodRegionMapping', 'map', 'WITH', 'map.fkOrderShippingMethod = method.id')
->where('price.fkProductType = :fkProductType')
->andwhere('price.fkBrand = :fkBrand')
->andwhere('map.fkRegion = :fkRegion')
->setParameters([
'fkProductType' => $fkProductType,
'fkBrand' => $fkBrand,
'fkRegion' => $regionID,
])
->getQuery()
->setFetchMode("OrderCart", "address", \Doctrine\ORM\Mapping\ClassMetadata::FETCH_EAGER)
->getResult();
See the documentation :
// Example - $qb->innerJoin('u.Group', 'g', Expr\Join::WITH, $qb->expr()->eq('u.status_id', '?1'))
// Example - $qb->innerJoin('u.Group', 'g', 'WITH', 'u.status = ?1')
// Example - $qb->innerJoin('u.Group', 'g', 'WITH', 'u.status = ?1', 'g.id')
public function innerJoin($join, $alias, $conditionType = null, $condition = null, $indexBy = null);

Semantical Error line 0, col 140 near 'Q INNER JOIN': Error: Class Search\serachBundle\Entity\Person has no association named Qualification

what's the wrong in this code
i want to create query with multi join but unfortunately this error displayed
[this is my SearchController controller]
class SearchController extends Controller {
public function indexAction() {
$em = $this->get('doctrine.orm.entity_manager');
$users = $em
->createQueryBuilder('P')
->select('P.pname, Q.qname,P.gender,P.phone,P.yearsOfExperience,P.graduationYear,c.cname')
->add('from', 'serachBundle:Person P')
->Join('P.Qualification', 'Q')
->Join('Q.Category', 'c')
->where('P.qualificationId=Q.id')
->andwhere('Q.categoryId=c.id')
->getQuery();
$user = $users->getResult();
print_r($user);
//qualification
$Qlist = $this->getDoctrine()
->getRepository('serachBundle:qualification')
->findAll();
//category
$Catlist = $this->getDoctrine()
->getRepository('serachBundle:category')
->findAll();
return $this->render('serachBundle:Default:Search.html.twig', array('user' => $user, 'Qlist' => $Qlist, 'Catlist' => $Catlist));
}
this my person entity
<?php
namespace Search\serachBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Person
*
* #ORM\Table(name="person", indexes={#ORM\Index(name="companyId", columns={"companyId", "qualificationId"}), #ORM\Index(name="qualificationId", columns={"qualificationId"}), #ORM\Index(name="IDX_34DCD1762480E723", columns={"companyId"})})
* #ORM\Entity
*/
class Person
{
/**
* #var string
*
* #ORM\Column(name="pname", type="string", length=255, nullable=false)
*/
private $pname;
/**
* #var string
*
* #ORM\Column(name="address", type="string", length=255, nullable=false)
*/
private $address;
/**
* #var string
*
* #ORM\Column(name="phone", type="string", length=255, nullable=false)
*/
private $phone;
/**
* #var string
*
* #ORM\Column(name="gender", type="string", length=255, nullable=false)
*/
private $gender;
/**
* #var integer
*
* #ORM\Column(name="yearsOfExperience", type="integer", nullable=false)
*/
private $yearsofexperience;
/**
* #var integer
*
* #ORM\Column(name="graduationYear", type="integer", nullable=false)
*/
private $graduationyear;
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var \Search\serachBundle\Entity\Company
*
* #ORM\ManyToOne(targetEntity="Search\serachBundle\Entity\Company")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="companyId", referencedColumnName="id")
* })
*/
private $companyid;
/**
* #var \Search\serachBundle\Entity\Qualification
*
* #ORM\ManyToOne(targetEntity="Search\serachBundle\Entity\Qualification")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="qualificationId", referencedColumnName="id")
* })
*/
private $qualificationid;
/**
* Set pname
*
* #param string $pname
* #return Person
*/
public function setPname($pname)
{
$this->pname = $pname;
return $this;
}
/**
* Get pname
*
* #return string
*/
public function getPname()
{
return $this->pname;
}
/**
* Set address
*
* #param string $address
* #return Person
*/
public function setAddress($address)
{
$this->address = $address;
return $this;
}
/**
* Get address
*
* #return string
*/
public function getAddress()
{
return $this->address;
}
/**
* Set phone
*
* #param string $phone
* #return Person
*/
public function setPhone($phone)
{
$this->phone = $phone;
return $this;
}
/**
* Get phone
*
* #return string
*/
public function getPhone()
{
return $this->phone;
}
/**
* Set gender
*
* #param string $gender
* #return Person
*/
public function setGender($gender)
{
$this->gender = $gender;
return $this;
}
/**
* Get gender
*
* #return string
*/
public function getGender()
{
return $this->gender;
}
/**
* Set yearsofexperience
*
* #param integer $yearsofexperience
* #return Person
*/
public function setYearsofexperience($yearsofexperience)
{
$this->yearsofexperience = $yearsofexperience;
return $this;
}
/**
* Get yearsofexperience
*
* #return integer
*/
public function getYearsofexperience()
{
return $this->yearsofexperience;
}
/**
* Set graduationyear
*
* #param integer $graduationyear
* #return Person
*/
public function setGraduationyear($graduationyear)
{
$this->graduationyear = $graduationyear;
return $this;
}
/**
* Get graduationyear
*
* #return integer
*/
public function getGraduationyear()
{
return $this->graduationyear;
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set companyid
*
* #param \Search\serachBundle\Entity\Company $companyid
* #return Person
*/
public function setCompanyid(\Search\serachBundle\Entity\Company $companyid = null)
{
$this->companyid = $companyid;
return $this;
}
/**
* Get companyid
*
* #return \Search\serachBundle\Entity\Company
*/
public function getCompanyid()
{
return $this->companyid;
}
/**
* Set qualificationid
*
* #param \Search\serachBundle\Entity\Qualification $qualificationid
* #return Person
*/
public function setQualificationid(\Search\serachBundle\Entity\Qualification $qualificationid = null)
{
$this->qualificationid = $qualificationid;
return $this;
}
/**
* Get qualificationid
*
* #return \Search\serachBundle\Entity\Qualification
*/
public function getQualificationid()
{
return $this->qualificationid;
}
}
(Entities are objects with identity. Their identity has a conceptual meaning inside your domain. In a CMS application each article has a unique id. You can uniquely identify each article by that id.)
this my Qualification entity
<?php
namespace Search\serachBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Qualification
*
* #ORM\Table(name="qualification", indexes={#ORM\Index(name="categoryId", columns={"categoryId"})})
* #ORM\Entity
*/
class Qualification
{
/**
* #var string
*
* #ORM\Column(name="qname", type="string", length=255, nullable=false)
*/
private $qname;
/**
* #var string
*
* #ORM\Column(name="specialty", type="string", length=255, nullable=false)
*/
private $specialty;
/**
* #var string
*
* #ORM\Column(name="qualifDesc", type="string", length=255, nullable=false)
*/
private $qualifdesc;
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var \Search\serachBundle\Entity\Category
*
* #ORM\ManyToOne(targetEntity="Search\serachBundle\Entity\Category")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="categoryId", referencedColumnName="id")
* })
*/
private $categoryid;
/**
* Set qname
*
* #param string $qname
* #return Qualification
*/
public function setQname($qname)
{
$this->qname = $qname;
return $this;
}
/**
* Get qname
*
* #return string
*/
public function getQname()
{
return $this->qname;
}
/**
* Set specialty
*
* #param string $specialty
* #return Qualification
*/
public function setSpecialty($specialty)
{
$this->specialty = $specialty;
return $this;
}
/**
* Get specialty
*
* #return string
*/
public function getSpecialty()
{
return $this->specialty;
}
/**
* Set qualifdesc
*
* #param string $qualifdesc
* #return Qualification
*/
public function setQualifdesc($qualifdesc)
{
$this->qualifdesc = $qualifdesc;
return $this;
}
/**
* Get qualifdesc
*
* #return string
*/
public function getQualifdesc()
{
return $this->qualifdesc;
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set categoryid
*
* #param \Search\serachBundle\Entity\Category $categoryid
* #return Qualification
*/
public function setCategoryid(\Search\serachBundle\Entity\Category $categoryid = null)
{
$this->categoryid = $categoryid;
return $this;
}
/**
* Get categoryid
*
* #return \Search\serachBundle\Entity\Category
*/
public function getCategoryid()
{
return $this->categoryid;
}
}
Thanks in advance if anyone can solve this. It would be a really great help
You named the relations as $qualificationid, so you should make your query something like this:
->Join('P.qualificationid', 'Q')
->Join('Q.categoryid', 'c')
Remember to make all queries inside repositories classes. And please, try to rename your bundle from serach to search :-D

Symfony Query doctrine entity

I have a problem with a query in doctrine i started using Symfony recently for to be continued a old project in Symfony and now i want learn it.
I start to explain from db and i write only the fields that interest me :
user(id,name,surname,phat)
user_reference(id,id_user[FOREIGN KEY id FROM user],id_user_referenced[FOREIGN KEY id FROM user])
This is the query :
$id_user = $user->getId();
$query = $em->createQueryBuilder()
->select('ur','uu')
->from('DtEcBundle:UserReferences', 'ur')
->innerJoin("ur.id_user","uu")
->where("ur.id_user = :id_user")
->setParameter("id_user",$id_user)
->getQuery();
$userpyramid = $query->getResult();
I print in my twig file id_user_referenced but i would print too "name, surname and path" from USER table
For print id_user_referenced in the Entity UserReferences there is this code:
/**
* Set id_user_referenced
*
* #param \Dt\EcBundle\Entity\User $idUserReferenced
* #return UserReferences
*/
public function setIdUserReferenced(\Dt\EcBundle\Entity\User $idUserReferenced = null) {
$this->id_user_referenced = $idUserReferenced;
return $this;
}
/**
* Get id_user_referenced
*
* #return \Dt\EcBundle\Entity\User
*/
public function getIdUserReferenced() {
return $this->id_user_referenced;
}
Transform a number like id to string in Entity User with:
public function __toString(){
return strval($this->id);
}
Now if i add to my query in the select this:
->select('ur','uu.path')
Symfony send me an error:
Key "idUserReferenced" for array with keys "0, path" does not exist in
DtEcBundle:Profilo:digitalpr-profile.html.twig at line 40
Why?? How can i solved it??
UserReferences.php
namespace Dt\EcBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* UserReferences
*
* #ORM\Table(name="user_references" ,uniqueConstraints= {#ORM\UniqueConstraint(name="recension_unique", columns={"id_user", "id_user_referenced"})})
* #ORM\Entity(repositoryClass="Dt\EcBundle\Entity\UserReferencesRepository")
*/ class UserReferences {
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
*
* #var Dt\EcBundle\Entity\User
* #ORM\ManyToOne(targetEntity="Dt\EcBundle\Entity\User", inversedBy="references")
* #ORM\JoinColumn(name="id_user", referencedColumnName="id")
*/
private $id_user;
/**
* #ORM\ManyToOne(targetEntity="Dt\EcBundle\Entity\User")
* #ORM\JoinColumn(name="id_user_referenced", referencedColumnName="id")
* */
private $id_user_referenced;
/**
*
* #var string
* #ORM\Column(name="reference", type="text", nullable=false,unique=false);
*/
private $reference;
/**
* Get id
*
* #return integer
*/
public function getId() {
return $this->id;
}
/**
* Set reference
*
* #param string $reference
* #return UserReferences
*/
public function setReference($reference) {
$this->reference = $reference;
return $this;
}
/**
* Get reference
*
* #return string
*/
public function getReference() {
return $this->reference;
}
/**
* Set id_user
*
* #param \Dt\EcBundle\Entity\User $idUser
* #return UserReferences
*/
public function setIdUser(\Dt\EcBundle\Entity\User $idUser = null) {
$this->id_user = $idUser;
return $this;
}
/**
* Get id_user
*
* #return \Dt\EcBundle\Entity\User
*/
public function getIdUser() {
return $this->id_user;
}
/**
* Set id_user_referenced
*
* #param \Dt\EcBundle\Entity\User $idUserReferenced
* #return UserReferences
*/
public function setIdUserReferenced(\Dt\EcBundle\Entity\User $idUserReferenced = null) {
$this->id_user_referenced = $idUserReferenced;
return $this;
}
/**
* Get id_user_referenced
*
* #return \Dt\EcBundle\Entity\User
*/
public function getIdUserReferenced() {
return $this->id_user_referenced;
}
}
User.php
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255, unique=false, nullable=false)
* #Assert\NotBlank(message="user.name.not.blank")
* #Assert\Length(
* min=2,
* max=150,
* minMessage="user.name.not.min",
* maxMessage="user.name.not.max" )
*/
protected $name;
/**
* #var string
*
* #ORM\Column(name="surname", type="string", length=255, unique=false, nullable=false)
* #Assert\NotBlank(message="user.surname.not.blank")
* #Assert\Length(
* min=2,
* max=150,
* minMessage="user.surname.not.min",
* maxMessage="user.surname.not.max" )
*/
protected $surname;
/**
* #var \DateTime
* #ORM\Column(name="borndate", type="datetime",unique=false,nullable=false)
*/
protected $borndate;
/**
*
* #var string
* #ORM\Column(name="tel", type="string",length=50, unique=true,nullable=true)
* #Assert\Regex("/[0-9]/")
*/
protected $tel;
/**
*
* #var string
* #ORM\Column(name="city", type="string",length=255,unique=false,nullable=true)
* #Assert\NotBlank(message="user.expert.city.not.blank",groups={"Expert"})
* #Assert\NotBlank(message="user.expert.city.not.blank",groups={"ExpertProfile"})
* #Assert\Length(
* min=2,
* max=150,
* minMessage="user.expert.city.not.min",
* maxMessage="user.expert.city.not.max", groups={"Expert"} )
* #Assert\Length(
* min=2,
* max=150,
* minMessage="user.expert.city.not.min",
* maxMessage="user.expert.city.not.max", groups={"ExpertProfile"} )
*/
protected $city;
/**
*
* #var string
* #ORM\Column(name="street", type="string",length=255,unique=false,nullable=true)
* #Assert\NotBlank(message="user.expert.street.not.blank",groups={"Expert"})
* #Assert\NotBlank(message="user.expert.street.not.blank",groups={"ExpertProfile"})
* #Assert\Length(
* min=2,
* max=150,
* minMessage="user.expert.street.not.min",
* maxMessage="user.expert.street.not.max", groups={"Expert"} )
* #Assert\Length(
* min=2,
* max=150,
* minMessage="user.expert.street.not.min",
* maxMessage="user.expert.street.not.max", groups={"ExpertProfile"} )
*/
protected $street;
/**
*
* #var type
*
* #Assert\File(
* maxSize = "1024k",
* mimeTypes = {"image/gif","image/jpeg","image/pjpeg","image/png"},
* mimeTypesMessage = "user.image.mimetypes",
* maxSizeMessage = "user.image.maxsize"
* )
* #Assert\NotBlank(message="user.expert.mandatory.photo",groups={"Expert"})
*
*/
protected $photo;
/**
* #ORM\Column(name="photo_path",type="string", length=255, nullable=true,unique=true)
*/
protected $path;
/**
* Membri per la gestione dei file
*
*/
The problem is that doctrine hydrates your result in Array Hydration mode, while you expect Object Hydraion.
In the first case you ask for 2 related objects and doctrine can link them. In the second you ask for an object and for a scalar value, and doctrine cannot link them, so it returns them in two separate fields of an result array.
So the result that you have got from $query->getResult() in case of select('ur','uu.path') is not an array of User objects, but an array of 2 fields - $result[0] where you have all found User objects, and $result['path'] for uu.path - because uu.path is scalar value rather than object.
So you need to make select('ur','uu') and address your result as $result->getIdUserReferenced()->getPath().
Or (if you want to save some resources, but I don't think it worth it) make select('ur','uu.path') and then make var_dump of result. And you will see how to address to what you need.
I try in this mode but is not good
$id_user = $user->getId();
$query = $em->createQueryBuilder()
->select('ur','uu')
->from('DtEcBundle:UserReferences', 'ur')
->innerJoin("ur.id_user","uu")
->where("ur.id_user = :id_user")
->setParameter("id_user",$id_user)
->getQuery();
$userpyramid = $query->getResult();
$form = $this->get('form.factory')->createNamedBuilder('form', 'form')
->setMethod('POST')
->setAction($this->generateUrl('profilo_secondlevel'))
->add('save', 'submit', ['label' => 'Prova'])
->getForm();*/
$result->getIdUserReferenced()->getPath();
return $this->render('DtEcBundle:Profilo:index.html.twig', array(
'user' => $user,
'tags' => $tags,
'followers' =>$followers,
'expert' =>$expert,
'user_expert' =>$user_expert,
'well_cat' =>$well_cat,
'user_notification' => $user_notifications,
"udputenti" => $udputenti,
"userpyramid" => $userpyramid,
"result"=> $result
//'form'=>$form->createView()
));`

Where query + Doctrine

I have table item with item_id, item_title, item_description, item_created, item_approved. I also have a table article with PK item_id (from item table) and article_body.
Now I would like to select all the articles where item.item_approved is NOT equal to NULL. But I'm stuck with creating the query. This is what I have now:
$entityManager = $this->getDoctrine()->getManager();
$repository = $entityManager->getRepository('VolleyScoutBundle:Article');
$query = $repository->createQueryBuilder('a')
->where('a.item.ItemApproved != NULL')
->getQuery();
$articles = $query->getResult();
This gave me the error: [Syntax Error] line 0, col 73: Error: Expected =, <, <=, <>, >, >=, !=, got '.'
This is my Article Entity:
<?php
namespace VolleyScout\VolleyScoutBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Article
*
* #ORM\Table(name="article")
* #ORM\Entity
*/
class Article
{
/**
* #var string
*
* #ORM\Column(name="article_body", type="text", nullable=false)
*/
private $articleBody;
/**
* #var \VolleyScout\VolleyScoutBundle\Entity\Item
*
* #ORM\Id
* #ORM\GeneratedValue(strategy="NONE")
* #ORM\OneToOne(targetEntity="VolleyScout\VolleyScoutBundle\Entity\Item")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="item_id", referencedColumnName="item_id")
* })
*/
private $item;
/**
* Set articleBody
*
* #param string $articleBody
* #return Article
*/
public function setArticleBody($articleBody)
{
$this->articleBody = $articleBody;
return $this;
}
/**
* Get articleBody
*
* #return string
*/
public function getArticleBody()
{
return $this->articleBody;
}
/**
* Set item
*
* #param \VolleyScout\VolleyScoutBundle\Entity\Item $item
* #return Article
*/
public function setItem(\VolleyScout\VolleyScoutBundle\Entity\Item $item)
{
$this->item = $item;
return $this;
}
/**
* Get item
*
* #return \VolleyScout\VolleyScoutBundle\Entity\Item
*/
public function getItem()
{
return $this->item;
}
}
This is my Item Entity:
<?php
namespace VolleyScout\VolleyScoutBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Item
*
* #ORM\Table(name="item", indexes={#ORM\Index(name="fk_item_users1_idx", columns={"user_id"}), #ORM\Index(name="fk_item_myteam1_idx", columns={"myteam_id"})})
* #ORM\Entity
*/
class Item
{
/**
* #var string
*
* #ORM\Column(name="item_title", type="string", length=255, nullable=false)
*/
private $itemTitle;
/**
* #var string
*
* #ORM\Column(name="item_description", type="text", nullable=false)
*/
private $itemDescription;
/**
* #var \DateTime
*
* #ORM\Column(name="item_created", type="datetime", nullable=false)
*/
private $itemCreated;
/**
* #var \DateTime
*
* #ORM\Column(name="item_approved", type="datetime", nullable=true)
*/
private $itemApproved;
/**
* #var \DateTime
*
* #ORM\Column(name="item_deleted", type="datetime", nullable=true)
*/
private $itemDeleted;
/**
* #var integer
*
* #ORM\Column(name="item_id", type="bigint")
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $itemId;
/**
* #var \VolleyScout\VolleyScoutBundle\Entity\Myteam
*
* #ORM\ManyToOne(targetEntity="VolleyScout\VolleyScoutBundle\Entity\Myteam")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="myteam_id", referencedColumnName="myteam_id")
* })
*/
private $myteam;
/**
* #var \VolleyScout\VolleyScoutBundle\Entity\Users
*
* #ORM\ManyToOne(targetEntity="VolleyScout\VolleyScoutBundle\Entity\Users")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="user_id", referencedColumnName="user_id")
* })
*/
private $user;
/**
* Set itemTitle
*
* #param string $itemTitle
* #return Item
*/
public function setItemTitle($itemTitle)
{
$this->itemTitle = $itemTitle;
return $this;
}
/**
* Get itemTitle
*
* #return string
*/
public function getItemTitle()
{
return $this->itemTitle;
}
/**
* Set itemDescription
*
* #param string $itemDescription
* #return Item
*/
public function setItemDescription($itemDescription)
{
$this->itemDescription = $itemDescription;
return $this;
}
/**
* Get itemDescription
*
* #return string
*/
public function getItemDescription()
{
return $this->itemDescription;
}
/**
* Set itemCreated
*
* #param \DateTime $itemCreated
* #return Item
*/
public function setItemCreated($itemCreated)
{
$this->itemCreated = $itemCreated;
return $this;
}
/**
* Get itemCreated
*
* #return \DateTime
*/
public function getItemCreated()
{
return $this->itemCreated;
}
/**
* Set itemApproved
*
* #param \DateTime $itemApproved
* #return Item
*/
public function setItemApproved($itemApproved)
{
$this->itemApproved = $itemApproved;
return $this;
}
/**
* Get itemApproved
*
* #return \DateTime
*/
public function getItemApproved()
{
return $this->itemApproved;
}
/**
* Set itemDeleted
*
* #param \DateTime $itemDeleted
* #return Item
*/
public function setItemDeleted($itemDeleted)
{
$this->itemDeleted = $itemDeleted;
return $this;
}
/**
* Get itemDeleted
*
* #return \DateTime
*/
public function getItemDeleted()
{
return $this->itemDeleted;
}
/**
* Get itemId
*
* #return integer
*/
public function getItemId()
{
return $this->itemId;
}
/**
* Set myteam
*
* #param \VolleyScout\VolleyScoutBundle\Entity\Myteam $myteam
* #return Item
*/
public function setMyteam(\VolleyScout\VolleyScoutBundle\Entity\Myteam $myteam = null)
{
$this->myteam = $myteam;
return $this;
}
/**
* Get myteam
*
* #return \VolleyScout\VolleyScoutBundle\Entity\Myteam
*/
public function getMyteam()
{
return $this->myteam;
}
/**
* Set user
*
* #param \VolleyScout\VolleyScoutBundle\Entity\Users $user
* #return Item
*/
public function setUser(\VolleyScout\VolleyScoutBundle\Entity\Users $user = null)
{
$this->user = $user;
return $this;
}
/**
* Get user
*
* #return \VolleyScout\VolleyScoutBundle\Entity\Users
*/
public function getUser()
{
return $this->user;
}
}
try:
$query = $repository->createQueryBuilder('a')
->join('a.item', 'i')
->where('i.ItemApproved is not NULL')
->getQuery();

Categories