Symfony2 / Doctrine, A new entity was found through the relationship - php

trying to fix this over 48 hours. I have an entity BookingRequest.php which content is:
<?php
namespace Kutiwa\PlatformBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* BookingRequest
*
* #ORM\Table(name="booking_request")
* #ORM\Entity(repositoryClass="Kutiwa\PlatformBundle\Repository\BookingRequestRepository")
*/
class BookingRequest
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="code", type="string", length=255, unique=true)
*/
private $code;
/**
* #var string
*
* #ORM\Column(name="arrival", type="string", length=255)
*/
private $arrival;
/**
* #var string
*
* #ORM\Column(name="departure", type="string", length=255)
*/
private $departure;
/**
* #var string
*
* #ORM\Column(name="requestDate", type="string", length=255)
*/
private $requestDate;
/**
* #var int
*
* #ORM\Column(name="rooms", type="integer")
*/
private $rooms;
/**
* #var string
*
* #ORM\Column(name="minPricing", type="string", length=255)
*/
private $minPricing;
/**
* #var string
*
* #ORM\Column(name="maxPricing", type="string", length=255)
*/
private $maxPricing;
/**
* #var string
*
* #ORM\Column(name="customerName", type="string", length=255)
*/
private $customerName;
/**
* #var string
*
* #ORM\Column(name="customerEmail", type="string", length=255, nullable=true)
*/
private $customerEmail;
/**
* #var string
*
* #ORM\Column(name="customerPhone", type="string", length=255)
*/
private $customerPhone;
/**
* #ORM\ManyToOne(targetEntity="Kutiwa\PlatformBundle\Entity\City")
* #ORM\JoinColumn(nullable=false)
*/
private $destinationCity;
/**
* #ORM\ManyToOne(targetEntity="Kutiwa\PlatformBundle\Entity\City")
* #ORM\JoinColumn(nullable=false)
*/
private $customerCity;
/**
* #ORM\OneToOne(targetEntity="Kutiwa\PlatformBundle\Entity\MissionConfig", cascade={"persist"})
*/
private $missionConfig;
/**
* #ORM\OneToOne(targetEntity="Kutiwa\PlatformBundle\Entity\TourismConfig", cascade={"persist"})
*/
private $tourismConfig;
/**
* #ORM\OneToMany(targetEntity="Kutiwa\PlatformBundle\Entity\RoomsConfig", mappedBy="bookingRequest")
*/
private $roomsConfigs;
public function __construct() {
$this->setRequestDate(date("d/m/Y"));
}
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set code
*
* #param string $code
*
* #return BookingRequest
*/
public function setCode($code)
{
$this->code = $code;
return $this;
}
/**
* Get code
*
* #return string
*/
public function getCode()
{
return $this->code;
}
/**
* Set arrival
*
* #param string $arrival
*
* #return BookingRequest
*/
public function setArrival($arrival)
{
$this->arrival = $arrival;
return $this;
}
/**
* Get arrival
*
* #return string
*/
public function getArrival()
{
return $this->arrival;
}
/**
* Set departure
*
* #param string $departure
*
* #return BookingRequest
*/
public function setDeparture($departure)
{
$this->departure = $departure;
return $this;
}
/**
* Get departure
*
* #return string
*/
public function getDeparture()
{
return $this->departure;
}
/**
* Set requestDate
*
* #param string $requestDate
*
* #return BookingRequest
*/
public function setRequestDate($requestDate)
{
$this->requestDate = $requestDate;
return $this;
}
/**
* Get requestDate
*
* #return string
*/
public function getRequestDate()
{
return $this->requestDate;
}
/**
* Set rooms
*
* #param integer $rooms
*
* #return BookingRequest
*/
public function setRooms($rooms)
{
$this->rooms = $rooms;
return $this;
}
/**
* Get rooms
*
* #return integer
*/
public function getRooms()
{
return $this->rooms;
}
/**
* Set minPricing
*
* #param string $minPricing
*
* #return BookingRequest
*/
public function setMinPricing($minPricing)
{
$this->minPricing = $minPricing;
return $this;
}
/**
* Get minPricing
*
* #return string
*/
public function getMinPricing()
{
return $this->minPricing;
}
/**
* Set maxPricing
*
* #param string $maxPricing
*
* #return BookingRequest
*/
public function setMaxPricing($maxPricing)
{
$this->maxPricing = $maxPricing;
return $this;
}
/**
* Get maxPricing
*
* #return string
*/
public function getMaxPricing()
{
return $this->maxPricing;
}
/**
* Set customerName
*
* #param string $customerName
*
* #return BookingRequest
*/
public function setCustomerName($customerName)
{
$this->customerName = $customerName;
return $this;
}
/**
* Get customerName
*
* #return string
*/
public function getCustomerName()
{
return $this->customerName;
}
/**
* Set customerEmail
*
* #param string $customerEmail
*
* #return BookingRequest
*/
public function setCustomerEmail($customerEmail)
{
$this->customerEmail = $customerEmail;
return $this;
}
/**
* Get customerEmail
*
* #return string
*/
public function getCustomerEmail()
{
return $this->customerEmail;
}
/**
* Set customerPhone
*
* #param string $customerPhone
*
* #return BookingRequest
*/
public function setCustomerPhone($customerPhone)
{
$this->customerPhone = $customerPhone;
return $this;
}
/**
* Get customerPhone
*
* #return string
*/
public function getCustomerPhone()
{
return $this->customerPhone;
}
/**
* Set destinationCity
*
* #param \Kutiwa\PlatformBundle\Entity\City $destinationCity
*
* #return BookingRequest
*/
public function setDestinationCity(\Kutiwa\PlatformBundle\Entity\City $destinationCity)
{
$this->destinationCity = $destinationCity;
return $this;
}
/**
* Get destinationCity
*
* #return \Kutiwa\PlatformBundle\Entity\City
*/
public function getDestinationCity()
{
return $this->destinationCity;
}
/**
* Set customerCity
*
* #param \Kutiwa\PlatformBundle\Entity\City $customerCity
*
* #return BookingRequest
*/
public function setCustomerCity(\Kutiwa\PlatformBundle\Entity\City $customerCity)
{
$this->customerCity = $customerCity;
return $this;
}
/**
* Get customerCity
*
* #return \Kutiwa\PlatformBundle\Entity\City
*/
public function getCustomerCity()
{
return $this->customerCity;
}
/**
* Set missionConfig
*
* #param \Kutiwa\PlatformBundle\Entity\MissionConfig $missionConfig
*
* #return BookingRequest
*/
public function setMissionConfig(\Kutiwa\PlatformBundle\Entity\MissionConfig $missionConfig = null)
{
$this->missionConfig = $missionConfig;
return $this;
}
/**
* Get missionConfig
*
* #return \Kutiwa\PlatformBundle\Entity\MissionConfig
*/
public function getMissionConfig()
{
return $this->missionConfig;
}
/**
* Set tourismConfig
*
* #param \Kutiwa\PlatformBundle\Entity\TourismConfig $tourismConfig
*
* #return BookingRequest
*/
public function setTourismConfig(\Kutiwa\PlatformBundle\Entity\TourismConfig $tourismConfig = null)
{
$this->tourismConfig = $tourismConfig;
return $this;
}
/**
* Get tourismConfig
*
* #return \Kutiwa\PlatformBundle\Entity\TourismConfig
*/
public function getTourismConfig()
{
return $this->tourismConfig;
}
/**
* Add roomsConfig
*
* #param \Kutiwa\PlatformBundle\Entity\RoomsConfig $roomsConfig
*
* #return BookingRequest
*/
public function addRoomsConfig(\Kutiwa\PlatformBundle\Entity\RoomsConfig $roomsConfig)
{
$this->roomsConfigs[] = $roomsConfig;
return $this;
}
/**
* Remove roomsConfig
*
* #param \Kutiwa\PlatformBundle\Entity\RoomsConfig $roomsConfig
*/
public function removeRoomsConfig(\Kutiwa\PlatformBundle\Entity\RoomsConfig $roomsConfig)
{
$this->roomsConfigs->removeElement($roomsConfig);
}
/**
* Get roomsConfigs
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getRoomsConfigs()
{
return $this->roomsConfigs;
}
}
and another entity RoomsConfig.php
<?php
namespace Kutiwa\PlatformBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* RoomsConfig
*
* #ORM\Table(name="rooms_config")
* #ORM\Entity(repositoryClass="Kutiwa\PlatformBundle\Repository\RoomsConfigRepository")
*/
class RoomsConfig
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var bool
*
* #ORM\Column(name="airConditionner", type="boolean")
*/
private $airConditionner;
/**
* #var bool
*
* #ORM\Column(name="wifi", type="boolean")
*/
private $wifi;
/**
* #var bool
*
* #ORM\Column(name="balcony", type="boolean")
*/
private $balcony;
/**
* #var string
*
* #ORM\Column(name="tv", type="boolean")
*/
private $tv;
/**
* #ORM\ManyToOne(targetEntity="Kutiwa\PlatformBundle\Entity\BookingRequest", inversedBy="roomsConfigs", cascade={"persist"})
* #ORM\JoinColumn(nullable=false)
*/
private $bookingRequest;
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set airConditionner
*
* #param boolean $airConditionner
*
* #return RoomsConfig
*/
public function setAirConditionner($airConditionner)
{
$this->airConditionner = $airConditionner;
return $this;
}
/**
* Get airConditionner
*
* #return boolean
*/
public function getAirConditionner()
{
return $this->airConditionner;
}
/**
* Set wifi
*
* #param boolean $wifi
*
* #return RoomsConfig
*/
public function setWifi($wifi)
{
$this->wifi = $wifi;
return $this;
}
/**
* Get wifi
*
* #return boolean
*/
public function getWifi()
{
return $this->wifi;
}
/**
* Set balcony
*
* #param boolean $balcony
*
* #return RoomsConfig
*/
public function setBalcony($balcony)
{
$this->balcony = $balcony;
return $this;
}
/**
* Get balcony
*
* #return boolean
*/
public function getBalcony()
{
return $this->balcony;
}
/**
* Set tv
*
* #param boolean $tv
*
* #return RoomsConfig
*/
public function setTv($tv)
{
$this->tv = $tv;
return $this;
}
/**
* Get tv
*
* #return boolean
*/
public function getTv()
{
return $this->tv;
}
/**
* Set bookingRequest
*
* #param \Kutiwa\PlatformBundle\Entity\BookingRequest $bookingRequest
*
* #return RoomsConfig
*/
public function setBookingRequest(\Kutiwa\PlatformBundle\Entity\BookingRequest $bookingRequest)
{
$this->bookingRequest = $bookingRequest;
$bookingRequest->addRoomsConfig($this);
return $this;
}
/**
* Get bookingRequest
*
* #return \Kutiwa\PlatformBundle\Entity\BookingRequest
*/
public function getBookingRequest()
{
return $this->bookingRequest;
}
}
The problem is, when I try to persist a RoomsConfig entity, I got an error
A new entity was found through the relationship
'Kutiwa\PlatformBundle\Entity\BookingRequest#destinationCity' that was
not configured to cascade persist operations for entity: TIKO. To
solve this issue: Either explicitly call EntityManager#persist() on
this unknown entity or configure cascade persist this association in
the mapping for example #ManyToOne(..,cascade={"persist"})
I don't need a cascade effect on City and BookingRequest relation, here is my BookingRequestType.php
<?php
namespace Kutiwa\PlatformBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\OptionsResolver\OptionsResolver;
class BookingRequestType extends AbstractType
{
/**
* {#inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('arrival', TextType::class)
->add('departure', TextType::class)
->add('rooms', IntegerType::class)
->add('customerName', TextType::class)
->add('customerEmail', TextType::class, array('required' => false))
->add('customerPhone', TextType::class)
->add('destinationCity', EntityType::class, array(
'choice_label' => 'name',
'class' => 'KutiwaPlatformBundle:City'
))
->add('customerCity', EntityType::class, array(
'choice_label' => 'name',
'class' => 'KutiwaPlatformBundle:City'
));
}
/**
* {#inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Kutiwa\PlatformBundle\Entity\BookingRequest'
));
}
/**
* {#inheritdoc}
*/
public function getBlockPrefix()
{
return 'kutiwa_platformbundle_bookingrequest';
}
}
If I try to persist only BookingRequest entity, there is no problem, but when I persist RoomsConfig entity, I got that error. Help please. Thks.

Before persist your RoomsConfig, try to use findOneBy to find BookingRequest, or whatever you use to find the entity, and then set the found entity with setBookingRequest.

Related

Mapping Exception in Symfony / Doctrine: The target-entity App\DocumentBundle\File cannot be found in 'App\DocumentBundle\Entity\Document#file'

I'm trying to upgrade an application running on Symfony 3.4 to version 4.4. I already did multiple changes and adaptions according to the official documentation for upgrading Symfony. Neverthelesse, I'm stuck now with the following error that comes up when I try to run a command in the terminal or access the application via browser.
Mapping Exception
Doctrine\ORM\Mapping\MappingException:
The target-entity App\DocumentBundle\File cannot be found in 'App\DocumentBundle\Entity\Document#file'.
at /srv/http/sp7/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/MappingException.php:772
at Doctrine\ORM\Mapping\MappingException::invalidTargetEntityClass('App\\DocumentBundle\\File', 'App\\DocumentBundle\\Entity\\Document', 'file')
(/srv/http/sp7/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php:1032)
at Doctrine\ORM\Mapping\ClassMetadataInfo->validateAssociations()
(/srv/http/sp7/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:266)
at Doctrine\ORM\Mapping\ClassMetadataFactory->validateRuntimeMetadata(object(ClassMetadata), object(ClassMetadata))
(/srv/http/sp7/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:245)
at Doctrine\ORM\Mapping\ClassMetadataFactory->doLoadMetadata(object(ClassMetadata), object(ClassMetadata), false, array())
(/srv/http/sp7/vendor/doctrine/persistence/lib/Doctrine/Persistence/Mapping/AbstractClassMetadataFactory.php:306)
at Doctrine\Persistence\Mapping\AbstractClassMetadataFactory->loadMetadata('App\\DocumentBundle\\Entity\\Document')
(/srv/http/sp7/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:78)
at Doctrine\ORM\Mapping\ClassMetadataFactory->loadMetadata('App\\DocumentBundle\\Entity\\Document')
(/srv/http/sp7/vendor/doctrine/persistence/lib/Doctrine/Persistence/Mapping/AbstractClassMetadataFactory.php:185)
at Doctrine\Persistence\Mapping\AbstractClassMetadataFactory->getMetadataFor('App\\DocumentBundle\\Entity\\Document')
(/srv/http/sp7/vendor/doctrine/persistence/lib/Doctrine/Persistence/Mapping/AbstractClassMetadataFactory.php:91)
at Doctrine\Persistence\Mapping\AbstractClassMetadataFactory->getAllMetadata()
(/srv/http/sp7/vendor/mgilet/notification-bundle/NotifiableDiscovery.php:76)
at Mgilet\NotificationBundle\NotifiableDiscovery->discoverNotifiables()
(/srv/http/sp7/vendor/mgilet/notification-bundle/NotifiableDiscovery.php:40)
at Mgilet\NotificationBundle\NotifiableDiscovery->__construct(object(EntityManager), object(CachedReader))
(/srv/http/sp7/var/cache/dev/ContainerSAZB8iG/srcApp_KernelDevDebugContainer.php:6135)
at ContainerSAZB8iG\srcApp_KernelDevDebugContainer->getMgilet_NotificationService()
(/srv/http/sp7/var/cache/dev/ContainerSAZB8iG/srcApp_KernelDevDebugContainer.php:7481)
at ContainerSAZB8iG\srcApp_KernelDevDebugContainer->getTwigService()
(/srv/http/sp7/var/cache/dev/ContainerSAZB8iG/srcApp_KernelDevDebugContainer.php:13406)
at ContainerSAZB8iG\srcApp_KernelDevDebugContainer->getSensioFrameworkExtra_View_ListenerService()
(/srv/http/sp7/var/cache/dev/ContainerSAZB8iG/srcApp_KernelDevDebugContainer.php:4501)
at ContainerSAZB8iG\srcApp_KernelDevDebugContainer->ContainerSAZB8iG\{closure}()
(/srv/http/sp7/vendor/symfony/event-dispatcher/EventDispatcher.php:301)
at Symfony\Component\EventDispatcher\EventDispatcher::Symfony\Component\EventDispatcher\{closure}(object(ControllerEvent), 'kernel.controller', object(EventDispatcher))
(/srv/http/sp7/vendor/symfony/event-dispatcher/EventDispatcher.php:264)
at Symfony\Component\EventDispatcher\EventDispatcher->doDispatch(array(object(Closure), object(Closure), object(Closure), object(Closure), object(Closure), object(Closure)), 'kernel.controller', object(ControllerEvent))
(/srv/http/sp7/vendor/symfony/event-dispatcher/EventDispatcher.php:239)
at Symfony\Component\EventDispatcher\EventDispatcher->callListeners(array(object(Closure), object(Closure), object(Closure), object(Closure), object(Closure), object(Closure)), 'kernel.controller', object(ControllerEvent))
(/srv/http/sp7/vendor/symfony/event-dispatcher/EventDispatcher.php:73)
at Symfony\Component\EventDispatcher\EventDispatcher->dispatch(object(ControllerEvent), 'kernel.controller')
(/srv/http/sp7/vendor/symfony/http-kernel/HttpKernel.php:134)
at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
(/srv/http/sp7/vendor/symfony/http-kernel/HttpKernel.php:68)
at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
(/srv/http/sp7/vendor/symfony/http-kernel/Kernel.php:201)
at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
(/srv/http/sp7/public/index.php:25)
The code itself should store a document and offer the possibility to attach files to the documents. Therefore, I used the Vich/Uploader-Bundle and I suspect that the error somehow is linked to Vich.
Document.php
<?php
namespace App\DocumentBundle\Entity;
use App\Entity\FileAwareEntity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Bundle\DoctrineBundle\Registry;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\ExecutionContextInterface;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Security\Core\Security;
use App\UserBundle\Entity\User as User;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* #ORM\HasLifecycleCallbacks()
* #ORM\Table(name="document_document", options={"engine"="InnoDB"})
* #ORM\Entity(repositoryClass="App\DocumentBundle\Entity\DocumentRepository")
*/
class Document extends FileAwareEntity {
/**
* #ORM\Column(type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #Assert\NotBlank()
* #var string
* #ORM\Column(type="string")
* #Groups({"elastica"})
*/
private $name;
/**
*
* #var string
* #ORM\Column(type="text", nullable=true)
* #Groups({"elastica"})
*/
private $description;
/**
*
* #var string
* #ORM\Column(type="string", nullable=true)
* #Groups({"elastica"})
*/
private $headline;
/**
* #ORM\ManyToOne(targetEntity="App\DocumentBundle\Entity\DocumentType")
* #ORM\JoinColumn(name="type", referencedColumnName="id")
* #ORM\OrderBy({"translationKey" = "ASC"})
* #var \App\DocumentBundle\Entity\DocumentType
* #Groups({"elastica"})
**/
private $type;
/**
* #var string
* #ORM\Column(type="string", nullable=true)
* #Groups({"elastica"})
*/
private $vkaNumber;
/**
* #ORM\Column(type="string", length=255, nullable=true)
*/
private $linkedDocument;
/**
* #var string
* #ORM\Column(type="string", nullable=true)
*/
private $linkedDocumentExpires;
/**
* #var boolean
* #ORM\Column(type="boolean", nullable=true)
* #Groups({"elastica"})
*/
private $active;
/**
* #var boolean
* #ORM\Column(type="boolean", nullable=true)
*/
private $status_stealth;
/**
* #var boolean
* #ORM\Column(type="boolean", nullable=true)
*/
private $locked;
/**
* $var DateTime
* #ORM\Column(type="datetime", nullable=true)
* #Groups({"elastica"})
*/
private $created;
// * #Groups({"elastica"})
/**
* #ORM\ManyToOne(targetEntity="App\UserBundle\Entity\User", inversedBy="documentsCreated")
* #ORM\JoinColumn(name="createdBy", referencedColumnName="id")
* #var \App\UserBundle\Entity\User
**/
private $createdBy;
/**
* $var DateTime
* #ORM\Column(type="datetime", nullable=true)
* #Assert\Expression(
* "false == this.getStealthException()",
* message="The effective date must be in the future!")
* #Groups({"elastica"})
*/
private $effective;
/**
* $var DateTime
* #ORM\Column(type="datetime", nullable=true)
* #Assert\Expression(
* "this.getEffective() < this.getExpires()",
* message="The expiration date can't be before the effective date")
*/
private $expires;
/**
* $var DateTime
* #ORM\Column(type="datetime", nullable=true)
*/
private $modified;
/**
* #ORM\ManyToOne(targetEntity="App\UserBundle\Entity\User")
* #ORM\JoinColumn(name="modifiedBy", referencedColumnName="id")
* #var \App\UserBundle\Entity\User
**/
private $modifiedBy;
// * #Groups({"elastica"})
/**
* #ORM\ManyToMany(targetEntity="App\Entity\Agency", inversedBy="documentagency", cascade={"persist"})
* #ORM\JoinTable(name="document_document_agency",
* joinColumns={#ORM\JoinColumn(name="document_id", referencedColumnName="id")},
* inverseJoinColumns={#ORM\JoinColumn(name="iata8", referencedColumnName="iata8")})
* #var \App\Entity\Agency
**/
private $agency;
/**
* $var boolean
* #ORM\Column(type="boolean", nullable=true)
*/
private $signature;
/**
* $var boolean
* #ORM\Column(type="boolean", nullable=true)
*/
private $signed;
/**
* #ORM\ManyToOne(targetEntity="App\UserBundle\Entity\User", inversedBy="documentSigned")
* #ORM\JoinColumn(name="signedBy", referencedColumnName="id")
* #var \App\UserBundle\Entity\User
**/
private $signedBy;
/**
* #ORM\OneToMany(targetEntity="App\DocumentBundle\Entity\Comment", mappedBy="document",cascade={"remove"})
* #var \Doctrine\Common\Collections\Collection
**/
protected $comment;
// * #Groups({"elastica"})
/**
* #ORM\ManyToMany(targetEntity="App\Entity\Market", inversedBy="document", cascade={"persist"})
* #ORM\JoinTable(name="document_document_market",
* joinColumns={#ORM\JoinColumn(name="document_id", referencedColumnName="id")},
* inverseJoinColumns={#ORM\JoinColumn(name="market_id", referencedColumnName="id")})
* #Assert\Count(
* min = "0"
* )
**/
private $market;
// * #Groups({"elastica"})
/**
* #ORM\ManyToMany(targetEntity="App\Entity\Airline", inversedBy="document", cascade={"persist"})
* #ORM\JoinTable(name="document_document_airline",
* joinColumns={#ORM\JoinColumn(name="document_id", referencedColumnName="id")},
* inverseJoinColumns={#ORM\JoinColumn(name="airline_id", referencedColumnName="id")})
* #Assert\Count(
* min = "0"
* )
* #var \App\Entity\Airline
**/
private $airline;
// * #Groups({"elastica"})
/**
* #ORM\ManyToMany(targetEntity="App\Entity\Product", inversedBy="document", cascade={"persist"})
* #ORM\JoinTable(name="document_document_product",
* joinColumns={#ORM\JoinColumn(name="document_id", referencedColumnName="id")},
* inverseJoinColumns={#ORM\JoinColumn(name="product_id", referencedColumnName="id")})
* #Assert\Count(
* min = "0"
* )
* #var \App\Entity\Product
**/
private $product;
// * #Groups({"elastica"})
/**
* #ORM\ManyToMany(targetEntity="App\ReferentialBundle\Entity\Channel1", inversedBy="document", cascade={"persist"})
* #ORM\JoinTable(name="document_document_channel",
* joinColumns={#ORM\JoinColumn(name="document_id", referencedColumnName="id")},
* inverseJoinColumns={#ORM\JoinColumn(name="channel_id", referencedColumnName="id")})
* #Assert\Count(
* min = "0"
* )
* #var \App\ReferentialBundle\Entity\Channel1
**/
private $channel;
/**
* $var boolean
* #ORM\Column(type="boolean", nullable=true)
*/
private $internalCom;
/**
* #ORM\OneToMany(targetEntity="App\DocumentBundle\File", mappedBy="entity", cascade={"persist", "merge", "remove"}, orphanRemoval=true)
* #Assert\Valid()
* #var \Doctrine\Common\Collections\Collection
**/
protected $file;
/**
* #ORM\ManyToOne(targetEntity="App\DocumentBundle\Entity\Status")
* #ORM\JoinColumn(name="status", referencedColumnName="id", nullable=false)
* #var \App\DocumentBundle\Entity\Status
* #Groups({"elastica"})
*/
private $status;
/**
* #ORM\ManyToMany(targetEntity="App\DocumentBundle\Entity\UploadProfile", inversedBy="documents", cascade={"persist"})
* #ORM\JoinTable(name="document_document_uploadprofile",
* joinColumns={#ORM\JoinColumn(name="document_id", referencedColumnName="id")},
* inverseJoinColumns={#ORM\JoinColumn(name="uploadprofile_id", referencedColumnName="id")})
* #var \App\DocumentBundle\Entity\UploadProfile
**/
protected $uploadprofile;
/**
* #ORM\Column(type="decimal", precision=7, scale=7, nullable = true)
*/
protected $esScore;
/**
* Constructor
*/
public function __construct()
{
$this->locked = false;
$this->signed = false;
$this->market = new \Doctrine\Common\Collections\ArrayCollection();
$this->agency = new \Doctrine\Common\Collections\ArrayCollection();
$this->channel = new \Doctrine\Common\Collections\ArrayCollection();
$this->product = new \Doctrine\Common\Collections\ArrayCollection();
}
/* Entity: Functions ************************************************************************/
public function getCurrentDate(){
return new \DateTime();
}
/**
* #ORM\PrePersist
*/
public function prePersist() {
date_default_timezone_set('Europe/Berlin');
if($this->created == null)
{
$this->created = new \DateTime("now");
}
$market = $this->getMarket();
if(count($this->getAgency()) > 0){
foreach($this->getAgency() as $agency) {
if(!$this->market->contains($agency->getMarket())) {
$this->addMarket($agency->getMarket());
}
}
}
}
/**
* #ORM\PreUpdate
*/
public function preUpdate() {
date_default_timezone_set('Europe/Berlin');
if($this->modified == null)
{
$this->modified = new \DateTime("now");
}
$market = $this->getMarket();
if(count($this->getAgency()) > 0){
foreach($this->getAgency() as $agency) {
if(!$this->market->contains($agency->getMarket())) {
$this->addMarket($agency->getMarket());
}
}
}
}
/**
* Get statusStealth
*
* #return boolean
*/
public function getStatusStealth()
{
return $this->status_stealth;
}
public function getStealthException(){
if ($this->getEffective() < $this->getCurrentDate() && $this->getStatusStealth() == true){
return true;
} else{
return false;
}
}
public function show()
{
return array(
"domain" => "document",
"id" => $this->id,
"info" => $this->getHeadline(),
"title" => $this->name . ' - ' . $this->vkaNumber,
"airlines" => $this->getAirline(),
"agencies" => $this->getAgency(),
"markets" => $this->getMarket(),
"vkaNumber" => $this->vkaNumber,
"path" => "documentBundle_view_document",
"pathVariable" => "id",
"pathValue" => $this->id,
"bootstrapColor" => 'primary',
);
}
/* Entity: Functions ************************************************************************/
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* #param string $name
*
* #return Document
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* Set description
*
* #param string $description
*
* #return Document
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* #return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set headline
*
* #param string $headline
*
* #return Document
*/
public function setHeadline($headline)
{
$this->headline = $headline;
return $this;
}
/**
* Get headline
*
* #return string
*/
public function getHeadline()
{
return $this->headline;
}
/**
* Set vkaNumber
*
* #param string $vkaNumber
*
* #return Document
*/
public function setVkaNumber($vkaNumber)
{
$this->vkaNumber = $vkaNumber;
return $this;
}
/**
* Get vkaNumber
*
* #return string
*/
public function getVkaNumber()
{
return $this->vkaNumber;
}
/**
* Set linkedDocument
*
* #param string $linkedDocument
*
* #return Document
*/
public function setLinkedDocument($linkedDocument)
{
$this->linkedDocument = $linkedDocument;
return $this;
}
/**
* Get linkedDocument
*
* #return string
*/
public function getLinkedDocument()
{
return $this->linkedDocument;
}
/**
* Set linkedDocumentExpires
*
* #param string $linkedDocumentExpires
*
* #return Document
*/
public function setLinkedDocumentExpires($linkedDocumentExpires)
{
$this->linkedDocumentExpires = $linkedDocumentExpires;
return $this;
}
/**
* Get linkedDocumentExpires
*
* #return string
*/
public function getLinkedDocumentExpires()
{
return $this->linkedDocumentExpires;
}
/**
* Set active
*
* #param boolean $active
*
* #return Document
*/
public function setActive($active)
{
$this->active = $active;
return $this;
}
/**
* Get active
*
* #return boolean
*/
public function getActive()
{
return $this->active;
}
/**
* Set statusStealth
*
* #param boolean $statusStealth
*
* #return Document
*/
public function setStatusStealth($statusStealth)
{
$this->status_stealth = $statusStealth;
return $this;
}
/**
* Set locked
*
* #param boolean $locked
*
* #return Document
*/
public function setLocked($locked)
{
$this->locked = $locked;
return $this;
}
/**
* Get locked
*
* #return boolean
*/
public function getLocked()
{
return $this->locked;
}
/**
* Set created
*
* #param \DateTime $created
*
* #return Document
*/
public function setCreated($created)
{
$this->created = $created;
return $this;
}
/**
* Get created
*
* #return \DateTime
*/
public function getCreated()
{
return $this->created;
}
/**
* Set effective
*
* #param \DateTime $effective
*
* #return Document
*/
public function setEffective($effective)
{
$this->effective = $effective;
return $this;
}
/**
* Get effective
*
* #return \DateTime
*/
public function getEffective()
{
return $this->effective;
}
/**
* Set expires
*
* #param \DateTime $expires
*
* #return Document
*/
public function setExpires($expires)
{
$this->expires = $expires;
return $this;
}
/**
* Get expires
*
* #return \DateTime
*/
public function getExpires()
{
return $this->expires;
}
/**
* Set modified
*
* #param \DateTime $modified
*
* #return Document
*/
public function setModified($modified)
{
$this->modified = $modified;
return $this;
}
/**
* Get modified
*
* #return \DateTime
*/
public function getModified()
{
return $this->modified;
}
/**
* Set signature
*
* #param boolean $signature
*
* #return Document
*/
public function setSignature($signature)
{
$this->signature = $signature;
return $this;
}
/**
* Get signature
*
* #return boolean
*/
public function getSignature()
{
return $this->signature;
}
/**
* Set signed
*
* #param boolean $signed
*
* #return Document
*/
public function setSigned($signed)
{
$this->signed = $signed;
return $this;
}
/**
* Get signed
*
* #return boolean
*/
public function getSigned()
{
return $this->signed;
}
/**
* Set internalCom
*
* #param boolean $internalCom
*
* #return Document
*/
public function setInternalCom($internalCom)
{
$this->internalCom = $internalCom;
return $this;
}
/**
* Get internalCom
*
* #return boolean
*/
public function getInternalCom()
{
return $this->internalCom;
}
/**
* Set esScore
*
* #param string $esScore
*
* #return Document
*/
public function setEsScore($esScore)
{
$this->esScore = $esScore;
return $this;
}
/**
* Get esScore
*
* #return string
*/
public function getEsScore()
{
return $this->esScore;
}
/**
* Set type
*
* #param \App\DocumentBundle\Entity\DocumentType $type
*
* #return Document
*/
public function setType(\App\DocumentBundle\Entity\DocumentType $type = null)
{
$this->type = $type;
return $this;
}
/**
* Get type
*
* #return \App\DocumentBundle\Entity\DocumentType
*/
public function getType()
{
return $this->type;
}
/**
* Set createdBy
*
* #param \App\UserBundle\Entity\User $createdBy
*
* #return Document
*/
public function setCreatedBy(\App\UserBundle\Entity\User $createdBy = null)
{
$this->createdBy = $createdBy;
return $this;
}
/**
* Get createdBy
*
* #return \App\UserBundle\Entity\User
*/
public function getCreatedBy()
{
return $this->createdBy;
}
/**
* Set modifiedBy
*
* #param \App\UserBundle\Entity\User $modifiedBy
*
* #return Document
*/
public function setModifiedBy(\App\UserBundle\Entity\User $modifiedBy = null)
{
$this->modifiedBy = $modifiedBy;
return $this;
}
/**
* Get modifiedBy
*
* #return \App\UserBundle\Entity\User
*/
public function getModifiedBy()
{
return $this->modifiedBy;
}
/**
* Add agency
*
* #param \App\Entity\Agency $agency
*
* #return Document
*/
public function addAgency(\App\Entity\Agency $agency)
{
$this->agency[] = $agency;
return $this;
}
/**
* Remove agency
*
* #param \App\Entity\Agency $agency
*/
public function removeAgency(\App\Entity\Agency $agency)
{
$this->agency->removeElement($agency);
}
/**
* Get agency
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getAgency()
{
return $this->agency;
}
/**
* Set signedBy
*
* #param \App\UserBundle\Entity\User $signedBy
*
* #return Document
*/
public function setSignedBy(\App\UserBundle\Entity\User $signedBy = null)
{
$this->signedBy = $signedBy;
return $this;
}
/**
* Get signedBy
*
* #return \App\UserBundle\Entity\User
*/
public function getSignedBy()
{
return $this->signedBy;
}
/**
* Add comment
*
* #param \App\DocumentBundle\Entity\Comment $comment
*
* #return Document
*/
public function addComment(\App\DocumentBundle\Entity\Comment $comment)
{
$this->comment[] = $comment;
return $this;
}
/**
* Remove comment
*
* #param \App\DocumentBundle\Entity\Comment $comment
*/
public function removeComment(\App\DocumentBundle\Entity\Comment $comment)
{
$this->comment->removeElement($comment);
}
/**
* Get comment
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getComment()
{
return $this->comment;
}
/**
* Add market
*
* #param \App\Entity\Market $market
*
* #return Document
*/
public function addMarket(\App\Entity\Market $market)
{
$this->market[] = $market;
return $this;
}
/**
* Remove market
*
* #param \App\Entity\Market $market
*/
public function removeMarket(\App\Entity\Market $market)
{
$this->market->removeElement($market);
}
/**
* Get market
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getMarket()
{
return $this->market;
}
/**
* Add airline
*
* #param \App\Entity\Airline $airline
*
* #return Document
*/
public function addAirline(\App\Entity\Airline $airline)
{
$this->airline[] = $airline;
return $this;
}
/**
* Remove airline
*
* #param \App\Entity\Airline $airline
*/
public function removeAirline(\App\Entity\Airline $airline)
{
$this->airline->removeElement($airline);
}
/**
* Get airline
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getAirline()
{
return $this->airline;
}
/**
* Add product
*
* #param \App\Entity\Product $product
*
* #return Document
*/
public function addProduct(\App\Entity\Product $product)
{
$this->product[] = $product;
return $this;
}
/**
* Remove product
*
* #param \App\Entity\Product $product
*/
public function removeProduct(\App\Entity\Product $product)
{
$this->product->removeElement($product);
}
/**
* Get product
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getProduct()
{
return $this->product;
}
/**
* Add channel
*
* #param \App\ReferentialBundle\Entity\Channel1 $channel
*
* #return Document
*/
public function addChannel(\App\ReferentialBundle\Entity\Channel1 $channel)
{
$this->channel[] = $channel;
return $this;
}
/**
* Remove channel
*
* #param \App\ReferentialBundle\Entity\Channel1 $channel
*/
public function removeChannel(\App\ReferentialBundle\Entity\Channel1 $channel)
{
$this->channel->removeElement($channel);
}
/**
* Get channel
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getChannel()
{
return $this->channel;
}
/**
* Get file
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getFile()
{
return $this->file;
}
}
File.php (child class)
<?php
namespace App\DocumentBundle;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\File as BaseFile;
/**
* This class extends the base file class. Only the mapped entity and table name are different.
*
* #ORM\HasLifecycleCallbacks()
* #ORM\Table(name="document_file")
* #ORM\Entity
*/
class File extends BaseFile {
/**
* #ORM\ManyToOne(targetEntity="App\DocumentBundle\Entity\Document", inversedBy="file")
* #ORM\JoinColumn(name="entity", referencedColumnName="id", nullable=true)
* #var \App\DocumentBundle\Entity\Document
*/
protected $entity;
}
I already tried to clean the cache, restart the server, update doctrine or commented the property out, but nothing has worked so far. Has anyone an idea how to ressolve this issue?

Issue when trying to use doctrine queryBuilder

I have two entities Categorie and ChampCat with ManyToMany relation and I want to get list of categories with related ChampCat by using doctrine QueryBuilder so I have used this query:
class CategorieRepository extends \Doctrine\ORM\EntityRepository
{
public function myFindCategories(array $tab){
$em = $this->getEntityManager();
$query = $em->select(array('cat', 'ch'))
->from('AnnonceBundle\Entity\Categorie', 'cat')
->join('cat.champsCat', 'ch')
->where('cat.id In (:tabOfIds)')
->setParameter('tabOfIds', array_values($tab))
->getQuery();
return $query->getResult();
}
}
Here u can see the Categorie Entity:
<?php
namespace AnnonceBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Categorie
*
* #ORM\Table(name="categorie")
* #ORM\Entity(repositoryClass="AnnonceBundle\Repository\CategorieRepository")
*/
class Categorie implements \JsonSerializable
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="refCat", type="string", length=100)
*/
private $refCat;
/**
* #var string
*
* #ORM\Column(name="libelleCat", type="string", length=50)
*/
private $libelleCat;
/**
* #ORM\ManyToMany(targetEntity="AnnonceBundle\Entity\ChampCat",cascade={"persist"})
*/
private $champsCat;
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set refCat
*
* #param string $refCat
*
* #return Categorie
*/
public function setRefCat($refCat)
{
$this->refCat = $refCat;
return $this;
}
/**
* Get refCat
*
* #return string
*/
public function getRefCat()
{
return $this->refCat;
}
/**
* Set libelleCat
*
* #param string $libelleCat
*
* #return Categorie
*/
public function setLibelleCat($libelleCat)
{
$this->libelleCat = $libelleCat;
return $this;
}
/**
* Get libelleCat
*
* #return string
*/
public function getLibelleCat()
{
return $this->libelleCat;
}
/**
* Set champsCat
*
* #param \AnnonceBundle\Entity\ChampCat $champsCat
*
* #return Categorie
*/
public function setChampsCat(\AnnonceBundle\Entity\ChampCat $champsCat = null)
{
$this->champsCat = $champsCat;
return $this;
}
/**
* Get champsCat
*
* #return \AnnonceBundle\Entity\ChampCat
*/
public function getChampsCat()
{
return $this->champsCat;
}
/**
* Constructor
*/
public function __construct()
{
$this->champsCat = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Add champsCat
*
* #param \AnnonceBundle\Entity\ChampCat $champsCat
*
* #return Categorie
*/
public function addChampsCat(\AnnonceBundle\Entity\ChampCat $champsCat)
{
$this->champsCat[] = $champsCat;
return $this;
}
/**
* Remove champsCat
*
* #param \AnnonceBundle\Entity\ChampCat $champsCat
*/
public function removeChampsCat(\AnnonceBundle\Entity\ChampCat $champsCat)
{
$this->champsCat->removeElement($champsCat);
}
function jsonSerialize()
{
return get_object_vars($this);
}
}
And this is ChamCat Entity:
<?php
namespace AnnonceBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* ChampCat
*
* #ORM\Table(name="champ_cat")
* #ORM\Entity(repositoryClass="AnnonceBundle\Repository\ChampCatRepository")
*/
class ChampCat implements \JsonSerializable
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
*#var string
*
* #ORM\Column(name="refCh", type="string")
*/
private $refCh;
/**
* #var string
*
* #ORM\Column(name="nom_ch", type="string", length=255)
*/
private $nomCh;
/**
* #var bool
*
* #ORM\Column(name="app_ch", type="boolean")
*/
private $appCh;
/**
* #var string
*
* #ORM\Column(name="format_ch", type="string", length=255)
*/
private $formatCh;
/**
* Get id
*
* #return string
*/
public function getId()
{
return $this->refCh;
}
/**
* Set refCh
*
* #param integer $refCh
* #return ChampCat
*/
public function setRefCh($refCh)
{
$this->refCh = $refCh;
return $this;
}
/**
* Get refCh
*
* #return integer
*/
public function getRefCh()
{
return $this->refCh;
}
/**
* Set nomCh
*
* #param string $nomCh
* #return ChampCat
*/
public function setNomCh($nomCh)
{
$this->nomCh = $nomCh;
return $this;
}
/**
* Get nomCh
*
* #return string
*/
public function getNomCh()
{
return $this->nomCh;
}
/**
* Set appCh
*
* #param boolean $appCh
* #return ChampCat
*/
public function setAppCh($appCh)
{
$this->appCh = $appCh;
return $this;
}
/**
* Get appCh
*
* #return boolean
*/
public function getAppCh()
{
return $this->appCh;
}
/**
* Set formatCh
*
* #param string $formatCh
* #return ChampCat
*/
public function setFormatCh($formatCh)
{
$this->formatCh = $formatCh;
return $this;
}
/**
* Get formatCh
*
* #return string
*/
public function getFormatCh()
{
return $this->formatCh;
}
function jsonSerialize()
{
return get_object_vars($this);
}
}
Unfortunately this query didn't work, so what am I missing ?
Is it working with this syntax?
public function myFindCategories(array $tab){
if(count($tab) == 0) return []; //or IN() will bug with an empty array
$query = $this->createQueryBuilder('cat')
->addSelect('ch')
->innerJoin('cat.champsCat', 'ch')
->where('cat.id in (:tabOfIds)')
->setParameter('tabOfIds', $tab)
->getQuery();
return $query->getResult();
}

Fill Selectbox with database data - Forms + Doctrine + Symfony 3

I am trying to populate my form with an List of Results from query with Doctrine
But i`m getting this error:
Catchable Fatal Error: Object of class AppBundle\Entity\Parceiros could not be converted to string
Here is my Form CoberturasType
namespace AppBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
class CoberturasType extends AbstractType
{
/**
* #param FormBuilderInterface $builder
* #param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('descricao')
->add('parceiro', EntityType::class, [
'class'=>'AppBundle:Parceiros',
])
;
}
/**
* #param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'AppBundle\Entity\Coberturas'
));
}
}
Here is my CoberturasEntity
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Coberturas
*
* #ORM\Table(name="coberturas")
* #ORM\Entity(repositoryClass="AppBundle\Repository\CoberturasRepository")
* #ORM\Entity()
* #ORM\HasLifecycleCallbacks()
*/
class Coberturas
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\ManyToOne(targetEntity="Parceiros")
* #ORM\JoinColumn(name="parceiro", referencedColumnName="id", nullable=false)
*/
protected $parceiro;
/**
* #var string
*
* #ORM\Column(name="descricao", type="string", length=120)
*/
private $descricao;
/**
* #var bool
*
* #ORM\Column(name="_ativo", type="boolean")
*/
private $ativo;
/**
* #var \DateTime
*
* #ORM\Column(name="created", type="datetime")
*/
private $created;
/**
* #var string
*
* #ORM\Column(name="updated", type="datetime")
*/
private $updated;
/**
* #var bool
*
* #ORM\Column(name="_deletado", type="boolean")
*/
private $deletado;
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set descricao
*
* #param string $descricao
*
* #return Coberturas
*/
public function setDescricao($descricao)
{
$this->descricao = $descricao;
return $this;
}
/**
* Get descricao
*
* #return string
*/
public function getDescricao()
{
return $this->descricao;
}
/**
* Set ativo
*
* #param boolean $ativo
*
* #return Coberturas
*/
public function setAtivo($ativo)
{
$this->ativo = $ativo;
return $this;
}
/**
* Get ativo
*
* #return bool
*/
public function getAtivo()
{
return $this->ativo;
}
/**
* Set created
*
* #param \DateTime $created
*
* #return Coberturas
*/
public function setCreated($created)
{
$this->created = $created;
return $this;
}
/**
* Get created
*
* #return \DateTime
*/
public function getCreated()
{
return $this->created;
}
/**
* Set updated
*
* #param string $updated
*
* #return Coberturas
*/
public function setUpdated($updated)
{
$this->updated = $updated;
return $this;
}
/**
* Get updated
*
* #return string
*/
public function getUpdated()
{
return $this->updated;
}
/**
* Set deletado
*
* #param boolean $deletado
*
* #return Coberturas
*/
public function setDeletado($deletado)
{
$this->deletado = $deletado;
return $this;
}
/**
* Get deletado
*
* #return bool
*/
public function getDeletado()
{
return $this->deletado;
}
/**
* #ORM\PrePersist
*/
public function setCreatedValue()
{
$this->created = new \DateTime();
}
/**
* #ORM\postUpdate
*/
public function setUpdatedValue()
{
$this->updated = new \DateTime();
}
/**
* Set parceiro
*
* #param \AppBundle\Entity\Parceiros $parceiro
*
* #return Coberturas
*/
public function setParceiro(\AppBundle\Entity\Parceiros $parceiro = null)
{
$this->parceiro = $parceiro;
return $this;
}
/**
* Get parceiro
*
* #return \AppBundle\Entity\Parceiros
*/
public function getParceiro()
{
return $this->parceiro;
}
}
Here is my ParceirosEntity
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Parceiros
*
* #ORM\Table(name="parceiros")
* #ORM\Entity(repositoryClass="AppBundle\Repository\ParceirosRepository")
* #ORM\Entity()
* #ORM\HasLifecycleCallbacks()
*/
class Parceiros
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
* #ORM\OneToMany(targetEntity="Coberturas", mappedBy="parceiro")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="razaoSocial", type="string", length=255)
*/
private $razaoSocial;
/**
* #var string
*
* #ORM\Column(name="nomeFantasia", type="string", length=255, nullable=true)
*/
private $nomeFantasia;
/**
* #var string
*
* #ORM\Column(name="cnpj", type="string", length=17, nullable=true)
*/
private $cnpj;
/**
* #var string
*
* #ORM\Column(name="inscEstadual", type="string", length=60, nullable=true)
*/
private $inscEstadual;
/**
* #var string
*
* #ORM\Column(name="cep", type="string", length=9, nullable=true)
*/
private $cep;
/**
* #var string
*
* #ORM\Column(name="endereco", type="string", length=160, nullable=true)
*/
private $endereco;
/**
* #var string
*
* #ORM\Column(name="numero", type="string", length=30, nullable=true)
*/
private $numero;
/**
* #var string
*
* #ORM\Column(name="complemento", type="string", length=30, nullable=true)
*/
private $complemento;
/**
* #var string
*
* #ORM\Column(name="bairro", type="string", length=80, nullable=true)
*/
private $bairro;
/**
* #var string
*
* #ORM\Column(name="cidade", type="string", length=100, nullable=true)
*/
private $cidade;
/**
* #var string
*
* #ORM\Column(name="estado", type="string", length=2, nullable=true)
*/
private $estado;
/**
* #var \DateTime
*
* #ORM\Column(name="created", type="datetime", nullable=true)
*/
private $created;
/**
* #var \DateTime
*
* #ORM\Column(name="updated", type="datetime", nullable=true)
*/
private $updated;
/**
* #var bool
*
* #ORM\Column(name="ativo", type="boolean", nullable=true)
*/
private $ativo = 1;
/**
* #var bool
*
* #ORM\Column(name="deletado", type="boolean", nullable=true)
*/
private $deletado = 0;
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set razaoSocial
*
* #param string $razaoSocial
*
* #return Parceiros
*/
public function setRazaoSocial($razaoSocial)
{
$this->razaoSocial = $razaoSocial;
return $this;
}
/**
* Get razaoSocial
*
* #return string
*/
public function getRazaoSocial()
{
return $this->razaoSocial;
}
/**
* Set nomeFantasia
*
* #param string $nomeFantasia
*
* #return Parceiros
*/
public function setNomeFantasia($nomeFantasia)
{
$this->nomeFantasia = $nomeFantasia;
return $this;
}
/**
* Get nomeFantasia
*
* #return string
*/
public function getNomeFantasia()
{
return $this->nomeFantasia;
}
/**
* Set cnpj
*
* #param string $cnpj
*
* #return Parceiros
*/
public function setCnpj($cnpj)
{
$this->cnpj = $cnpj;
return $this;
}
/**
* Get cnpj
*
* #return string
*/
public function getCnpj()
{
return $this->cnpj;
}
/**
* Set inscEstadual
*
* #param string $inscEstadual
*
* #return Parceiros
*/
public function setInscEstadual($inscEstadual)
{
$this->inscEstadual = $inscEstadual;
return $this;
}
/**
* Get inscEstadual
*
* #return string
*/
public function getInscEstadual()
{
return $this->inscEstadual;
}
/**
* Set cep
*
* #param string $cep
*
* #return Parceiros
*/
public function setCep($cep)
{
$this->cep = $cep;
return $this;
}
/**
* Get cep
*
* #return string
*/
public function getCep()
{
return $this->cep;
}
/**
* Set endereco
*
* #param string $endereco
*
* #return Parceiros
*/
public function setEndereco($endereco)
{
$this->endereco = $endereco;
return $this;
}
/**
* Get endereco
*
* #return string
*/
public function getEndereco()
{
return $this->endereco;
}
/**
* Set numero
*
* #param string $numero
*
* #return Parceiros
*/
public function setNumero($numero)
{
$this->numero = $numero;
return $this;
}
/**
* Get numero
*
* #return string
*/
public function getNumero()
{
return $this->numero;
}
/**
* Set complemento
*
* #param string $complemento
*
* #return Parceiros
*/
public function setComplemento($complemento)
{
$this->complemento = $complemento;
return $this;
}
/**
* Get complemento
*
* #return string
*/
public function getComplemento()
{
return $this->complemento;
}
/**
* Set bairro
*
* #param string $bairro
*
* #return Parceiros
*/
public function setBairro($bairro)
{
$this->bairro = $bairro;
return $this;
}
/**
* Get bairro
*
* #return string
*/
public function getBairro()
{
return $this->bairro;
}
/**
* Set cidade
*
* #param string $cidade
*
* #return Parceiros
*/
public function setCidade($cidade)
{
$this->cidade = $cidade;
return $this;
}
/**
* Get cidade
*
* #return string
*/
public function getCidade()
{
return $this->cidade;
}
/**
* Set estado
*
* #param string $estado
*
* #return Parceiros
*/
public function setEstado($estado)
{
$this->estado = $estado;
return $this;
}
/**
* Get estado
*
* #return string
*/
public function getEstado()
{
return $this->estado;
}
/**
* Set created
*
* #param \DateTime $created
*
* #return Parceiros
*/
public function setCreated($created)
{
$this->created = $created;
return $this;
}
/**
* Get created
*
* #return \DateTime
*/
public function getCreated()
{
return $this->created;
}
/**
* Set updated
*
* #param \DateTime $updated
*
* #return Parceiros
*/
public function setUpdated($updated)
{
$this->updated = $updated;
return $this;
}
/**
* Get updated
*
* #return \DateTime
*/
public function getUpdated()
{
return $this->updated;
}
/**
* Set ativo
*
* #param boolean $ativo
*
* #return Parceiros
*/
public function setAtivo($ativo)
{
$this->ativo = $ativo;
return $this;
}
/**
* Get ativo
*
* #return bool
*/
public function getAtivo()
{
return $this->ativo;
}
/**
* Set deletado
*
* #param boolean $deletado
*
* #return Parceiros
*/
public function setDeletado($deletado)
{
$this->deletado = $deletado;
return $this;
}
/**
* Get deletado
*
* #return bool
*/
public function getDeletado()
{
return $this->deletado;
}
/**
* #ORM\PrePersist
*/
public function setCreatedValue()
{
$this->created = new \DateTime();
}
/**
* #ORM\postUpdate
*/
public function setUpdatedValue()
{
$this->updated = new \DateTime();
}
}
I just wanna show an SelectBox to user select for what "parceiro" he wanna insert a new "cobertura".
Thanks for the help...

Doctrine2: how to get one of the inversed side entities with ManyToOne relationship for a given id

I've two doctrine entities with ManyToOne relationship:
/**
* #ORM\ManyToOne(targetEntity="Iballot\CmsBundle\Entity\PollingStation2", cascade={"persist"})
* #ORM\JoinColumn(nullable=false)
* #Expose
*/
private $pollingStation2;
and I'd like get a specific one result for a given PollingStation2 ID and I've try that but doesn't work:
public function getPresidential($polId)
{
$qb = $this->createQueryBuilder('r');
$qb->where('r.pollingStation2 = :polling_station2_id')
->setParameter('polling_station2_id', $polId);
return $qb->getQuery()
->getResult();
}
Entities
namespace Iballot\CmsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* PollingStation2
*
* #ORM\Table()
* #ORM\Entity(repositoryClass="Iballot\CmsBundle\Entity\PollingStation2Repository")
*/
class PollingStation2
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="verfierNumber", type="integer", length=255, nullable=true)
*/
protected $verfierNumber;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* #var string
*
* #ORM\Column(name="verifier_number", type="string", length=255)
*/
private $verifierNumber;
/**
* #var string
*
* #ORM\Column(name="address", type="string", length=255)
*/
private $address;
/**
* #ORM\OneToMany(targetEntity="Iballot\CmsBundle\Entity\PollingStation2", mappedBy="pollingStation")
*/
protected $result;
/**
* #ORM\ManyToOne(targetEntity="Iballot\CmsBundle\Entity\Constituency", cascade={"persist"})
* #ORM\JoinColumn(nullable=false)
*/
private $constituency;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
public function __toString() {
return $this->getName();
}
/**
* Set name
*
* #param string $name
*
* #return PollingStation2
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* Set address
*
* #param string $address
*
* #return PollingStation2
*/
public function setAddress($address)
{
$this->address = $address;
return $this;
}
/**
* Get address
*
* #return string
*/
public function getAddress()
{
return $this->address;
}
/**
* Set verifierNumber
*
* #param integer $verifierNumber
*
* #return PollingStation2
*/
public function setVerifierNumber($verifierNumber)
{
$this->verifierNumber = $verifierNumber;
return $this;
}
/**
* Get verifierNumber
*
* #return integer
*/
public function getVerifierNumber()
{
return $this->verifierNumber;
}
/**
* Set verfierNumber
*
* #param integer $verfierNumber
*
* #return PollingStation2
*/
public function setVerfierNumber($verfierNumber)
{
$this->verfierNumber = $verfierNumber;
return $this;
}
/**
* Get verfierNumber
*
* #return integer
*/
public function getVerfierNumber()
{
return $this->verfierNumber;
}
/**
* Set constituency
*
* #param \Iballot\CmsBundle\Entity\Constituency $constituency
*
* #return PollingStation2
*/
public function setConstituency(\Iballot\CmsBundle\Entity\Constituency $constituency)
{
$this->constituency = $constituency;
return $this;
}
/**
* Get constituency
*
* #return \Iballot\CmsBundle\Entity\Constituency
*/
public function getConstituency()
{
return $this->constituency;
}
/**
* Constructor
*/
public function __construct()
{
$this->result = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Add result
*
* #param \Iballot\CmsBundle\Entity\PollingStation2 $result
*
* #return PollingStation2
*/
public function addResult(\Iballot\CmsBundle\Entity\PollingStation2 $result)
{
$this->result[] = $result;
return $this;
}
/**
* Remove result
*
* #param \Iballot\CmsBundle\Entity\PollingStation2 $result
*/
public function removeResult(\Iballot\CmsBundle\Entity\PollingStation2 $result)
{
$this->result->removeElement($result);
}
/**
* Get result
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getResult()
{
return $this->result;
}
}

Order by an specific related field with doctrine2 findoneby functionality

I want to find one data with findbyone option but by accesing the related object. Next you'll find the two of the entities Im using.
Caja.php
<?php
namespace PD\AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use APY\DataGridBundle\Grid\Mapping as GRID;
/**
*
* #ORM\Entity
* #ORM\Table(name="caja")
*
*/
class Caja
{
/**
*
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue
*/
protected $id;
/**
* #ORM\Column(type="string", length=100)
* #GRID\Column(title="Número carton")
*/
protected $numero_carton;
/** #ORM\Column(type="string", length=100) */
protected $contiene_libreta_limite_inferior;
/** #ORM\Column(type="string", length=100) */
protected $contiene_libreta_limite_superior;
/**
* #ORM\Column(type="string", length=100)
* #GRID\Column(title="Libretas omitidas")
*/
protected $omite_libreta;
/**
* #ORM\Column(type="string", length=100)
* #GRID\Column(title="Total libretas")
*/
protected $total_libretas;
/** #ORM\ManyToOne(targetEntity="PD\AppBundle\Entity\Juego")
* #ORM\JoinColumn(name="juego_id", referencedColumnName="id")
* */
protected $juego;
/** #ORM\ManyToOne(targetEntity="PD\AppBundle\Entity\Usuario") **/
protected $usuario;
/**
* #ORM\Column(type="datetime", nullable=true)
* #GRID\Column(title="Fecha creación")
*/
protected $fecha_creacion;
/**
* #var boolean
*
* #ORM\Column(name="estado", type="string", length=50)
* #GRID\Column(title="Estado")
*/
protected $estado;
/*
* 1 = CREADO
* 2 = ASIGNADO_A_SUPERVISOR
* 3 = FINALIZADO_CON_EXITO
* 4 = FINALIZADO_CON_OBSERVACIONES
* 5 = DESHABILITADO
*
*/
/**
* #ORM\OneToMany(targetEntity="PD\AppBundle\Entity\Libreta", mappedBy="caja", cascade={"remove", "persist"})
*/
protected $libretas;
public function __construct()
{
$this->fecha_creacion = new \DateTime();
$this->libretas = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set numero_carton
*
* #param string $numeroCarton
* #return Caja
*/
public function setNumeroCarton($numeroCarton)
{
$this->numero_carton = $numeroCarton;
return $this;
}
/**
* Get numero_carton
*
* #return string
*/
public function getNumeroCarton()
{
return $this->numero_carton;
}
/**
* Set contiene_libreta_limite_inferior
*
* #param string $contieneLibretaLimiteInferior
* #return Caja
*/
public function setContieneLibretaLimiteInferior($contieneLibretaLimiteInferior)
{
$this->contiene_libreta_limite_inferior = $contieneLibretaLimiteInferior;
return $this;
}
/**
* Get contiene_libreta_limite_inferior
*
* #return string
*/
public function getContieneLibretaLimiteInferior()
{
return $this->contiene_libreta_limite_inferior;
}
/**
* Set contiene_libreta_limite_superior
*
* #param string $contieneLibretaLimiteSuperior
* #return Caja
*/
public function setContieneLibretaLimiteSuperior($contieneLibretaLimiteSuperior)
{
$this->contiene_libreta_limite_superior = $contieneLibretaLimiteSuperior;
return $this;
}
/**
* Get contiene_libreta_limite_superior
*
* #return string
*/
public function getContieneLibretaLimiteSuperior()
{
return $this->contiene_libreta_limite_superior;
}
/**
* Set omite_libreta
*
* #param string $omiteLibreta
* #return Caja
*/
public function setOmiteLibreta($omiteLibreta)
{
$this->omite_libreta = $omiteLibreta;
return $this;
}
/**
* Get omite_libreta
*
* #return string
*/
public function getOmiteLibreta()
{
return $this->omite_libreta;
}
/**
* Set total_libretas
*
* #param string $totalLibretas
* #return Caja
*/
public function setTotalLibretas($totalLibretas)
{
$this->total_libretas = $totalLibretas;
return $this;
}
/**
* Get total_libretas
*
* #return string
*/
public function getTotalLibretas()
{
return $this->total_libretas;
}
/**
* Set juego
*
* #param \PD\AppBundle\Entity\Juego $juego
* #return Caja
*/
public function setJuego(\PD\AppBundle\Entity\Juego $juego)
{
$this->juego = $juego;
}
/**
* Get juego
*
* #return \PD\AppBundle\Entity\Juego
*/
public function getJuego()
{
return $this->juego;
}
public function __toString()
{
return $this->getNumeroCarton();
}
/**
* Set usuario
*
* #param \PD\AppBundle\Entity\Usuario $usuario
* #return Caja
*/
public function setUsuario(\PD\AppBundle\Entity\Usuario $usuario)
{
$this->usuario = $usuario;
return $this;
}
/**
* Get usuario
*
* #return \PD\AppBundle\Entity\Usuario
*/
public function getUsuario()
{
return $this->usuario;
}
/**
* Set fecha_creacion
*
* #param \DateTime $fechaCreacion
* #return Caja
*/
public function setFechaCreacion($fechaCreacion)
{
$this->fecha_creacion = $fechaCreacion;
return $this;
}
/**
* Get fecha_creacion
*
* #return \DateTime
*/
public function getFechaCreacion()
{
return $this->fecha_creacion;
}
/**
* Set estado
*
* #param string $estado
* #return Caja
*/
public function setEstado($estado)
{
$this->estado = $estado;
return $this;
}
/**
* Get estado
*
* #return string
*/
public function getEstado()
{
return $this->estado;
}
/**
* Add libretas
*
* #param \PD\AppBundle\Entity\Libreta $libretas
* #return Caja
*/
public function addLibreta(\PD\AppBundle\Entity\Libreta $libretas)
{
//$this->libretas[] = $libretas;
//return $this;
$libretas->setCaja($this);
$this->libretas->add($libretas);
return $this;
}
/**
* Remove libretas
*
* #param \PD\AppBundle\Entity\Libreta $libretas
*/
public function removeLibreta(\PD\AppBundle\Entity\Libreta $libretas)
{
$this->libretas->removeElement($libretas);
}
/**
* Get libretas
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getLibretas()
{
return $this->libretas;
}
}
Libreta.php
<?php
namespace PD\AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use APY\DataGridBundle\Grid\Mapping as GRID;
/**
* Libreta
*
* #ORM\Table()
* #ORM\Entity
*/
class Libreta
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\ManyToOne(targetEntity="PD\AppBundle\Entity\Caja", inversedBy="libretas")
* #ORM\JoinColumn(name="caja_id", referencedColumnName="id", nullable=false)
* #Assert\Type(type="PD\AppBundle\Entity\Caja")
* #GRID\Column(field="caja.juego.nombre", title="Juego")
* #GRID\Column(field="caja.numero_carton", title="Caja")
*/
protected $caja;
/**
* #var string
*
* #ORM\Column(name="correlativo", type="string", length=10)
* #GRID\Column(title="Correlativo")
*/
private $correlativo;
/**
* #ORM\ManyToOne(targetEntity="PD\AppBundle\Entity\Usuario")
* #ORM\JoinColumn(name="vendedor_id", referencedColumnName="id", nullable=true)
* #Assert\Type(type="PD\AppBundle\Entity\Usuario")
* #GRID\Column(field="vendedor.nombre", title="Nombre vendedor")
* #GRID\Column(field="vendedor.apellidos", title="Apellidos vendedor")
*/
protected $vendedor;
/** #ORM\Column(name="precio_al_vendedor", type="decimal", scale=2) */
protected $precio_al_vendedor;
/** #ORM\Column(name="precio_acumulado", type="decimal", scale=2)
* #GRID\Column(title="Precio acumulado")
*/
protected $precio_acumulado;
/** #ORM\Column(name="premio_acumulado", type="decimal", scale=2)
* #GRID\Column(title="Premio acumulado")
*/
protected $premio_acumulado;
/**
* #ORM\Column(type="datetime", nullable=true)
*/
protected $fecha_asignacion_vendedor;
/**
* #ORM\Column(type="datetime", nullable=true)
*/
protected $fecha_estado_final;
/**
* #ORM\OneToMany(targetEntity="PD\AppBundle\Entity\Ticket", mappedBy="libreta", cascade={"persist"})
*/
protected $tickets;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set correlativo
*
* #param string $correlativo
* #return Libreta
*/
public function setCorrelativo($correlativo)
{
$this->correlativo = $correlativo;
return $this;
}
/**
* Get correlativo
*
* #return string
*/
public function getCorrelativo()
{
return $this->correlativo;
}
/**
* Set precio_al_vendedor
*
* #param string $precioAlVendedor
* #return Libreta
*/
public function setPrecioAlVendedor($precioAlVendedor)
{
$this->precio_al_vendedor = $precioAlVendedor;
return $this;
}
/**
* Get precio_al_vendedor
*
* #return string
*/
public function getPrecioAlVendedor()
{
return $this->precio_al_vendedor;
}
/**
* Set precio_acumulado
*
* #param string $precioAcumulado
* #return Libreta
*/
public function setPrecioAcumulado($precioAcumulado)
{
$this->precio_acumulado = $precioAcumulado;
return $this;
}
/**
* Get precio_acumulado
*
* #return string
*/
public function getPrecioAcumulado()
{
return $this->precio_acumulado;
}
/**
* Set fecha_asignacion_vendedor
*
* #param \DateTime $fechaAsignacionVendedor
* #return Libreta
*/
public function setFechaAsignacionVendedor($fechaAsignacionVendedor)
{
$this->fecha_asignacion_vendedor = $fechaAsignacionVendedor;
return $this;
}
/**
* Get fecha_asignacion_vendedor
*
* #return \DateTime
*/
public function getFechaAsignacionVendedor()
{
return $this->fecha_asignacion_vendedor;
}
/**
* Set fecha_estado_final
*
* #param \DateTime $fechaEstadoFinal
* #return Libreta
*/
public function setFechaEstadoFinal($fechaEstadoFinal)
{
$this->fecha_estado_final = $fechaEstadoFinal;
return $this;
}
/**
* Get fecha_estado_final
*
* #return \DateTime
*/
public function getFechaEstadoFinal()
{
return $this->fecha_estado_final;
}
/**
* Set vendedor
*
* #param \PD\AppBundle\Entity\Usuario $vendedor
* #return Libreta
*/
public function setVendedor(\PD\AppBundle\Entity\Usuario $vendedor = null)
{
$this->vendedor = $vendedor;
return $this;
}
/**
* Get vendedor
*
* #return \PD\AppBundle\Entity\Usuario
*/
public function getVendedor()
{
return $this->vendedor;
}
/**
* Set caja
*
* #param \PD\AppBundle\Entity\Caja $caja
* #return Libreta
*/
public function setCaja(\PD\AppBundle\Entity\Caja $caja = null)
{
$this->caja = $caja;
return $this;
}
/**
* Get caja
*
* #return \PD\AppBundle\Entity\Caja
*/
public function getCaja()
{
return $this->caja;
}
/**
* Constructor
*/
public function __construct()
{
$this->tickets = new \Doctrine\Common\Collections\ArrayCollection();
//$this->caja = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Add tickets
*
* #param \PD\AppBundle\Entity\Ticket $tickets
* #return Libreta
*/
public function addTicket(\PD\AppBundle\Entity\Ticket $tickets)
{
//$this->tickets[] = $tickets;
$tickets->setLibreta($this);
$this->tickets->add($tickets);
return $this;
}
/**
* Remove tickets
*
* #param \PD\AppBundle\Entity\Ticket $tickets
*/
public function removeTicket(\PD\AppBundle\Entity\Ticket $tickets)
{
$this->tickets->removeElement($tickets);
}
/**
* Get tickets
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getTickets()
{
return $this->tickets;
}
public function __toString()
{
return $this->correlativo;
}
/**
* Set premio_acumulado
*
* #param string $premioAcumulado
* #return Libreta
*/
public function setPremioAcumulado($premioAcumulado)
{
$this->premio_acumulado = $premioAcumulado;
return $this;
}
/**
* Get premio_acumulado
*
* #return string
*/
public function getPremioAcumulado()
{
return $this->premio_acumulado;
}
}
And what I would like to do is to find one next row ordered by field "fecha_creacion". This is what I have that get the next row but ordered by caja ID
$libreta_siguiente = $this->getDoctrine()
->getRepository('PDBundle:Libreta')
->findOneBy(array('vendedor' => NULL), array('caja' => 'DESC'));
But what I want to know if I can do something like "array('caja.fecha_creacion' => 'DESC'));". Until now, this part of the code isn't recognizing the "fecha_creacion" field
$libreta_siguiente = $this->getDoctrine()
->getRepository('PDBundle:Libreta')
->findOneBy(array('vendedor' => NULL), array('caja.fecha_creacion' => 'DESC'));
According to the doc, you can't pass a second parameter to the findOnyBy function.
But you can try to cheat by using the findBy methods and the position of this array :
$libreta_siguiente = $this->getDoctrine()
->getRepository('PDBundle:Libreta')
->findNextLibreta(NULL, $actualPosicion);
...
And in your repository :
public function findNextLibreta($vendedor, $posicion) {
$qb = $this->createQueryBuilder('l');
$qb->leftJoin(l.caja, 'c')
->where('l.vendedor = :vendedor')
->setParameter(':type', $type)
->orderBy('c.fecha_creacion', 'DESC');
$results = $qb->getQuery()->getResult();
return $results[$posicion];
}
Thanks to #JulienBourdic I changed a little his proposal but him basically gave me the answer. The code is:
$posicion = 0;
$libreta_siguiente = $this->getDoctrine()
->getRepository('PDBundle:Libreta')
->findByNextLibreta($posicion);
Then in LibretaRepository.php
public function findByNextLibreta($posicion) {
$qb = $this->createQueryBuilder('l');
$qb->leftJoin('l.caja', 'c')
->where('l.vendedor is NULL')
->orderBy('c.fecha_creacion', 'DESC');
$results = $qb->getQuery()->getResult();
return $results[$posicion];
}
It differs a little cuz didn't know how to pass the NULL value Julien was proposing so I used l.vendedor is NULL burned in the code.

Categories