Symfony2 After form submit entity not extended on base entity - php

In editAction method of controller I tried to edit existed entities in class table inheritance.
But after form submit I get error:
Neither the property "id" nor one of the methods
"addId()"/"removeId()", "setId()", "id()", "__set()" or "__call()"
exist and have public access in class "AdBundle\Entity\AdFlat".
Why AdFlat entity not extended of AdBase entity?
Base entity:
<?php
namespace AdBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* AdBase
*
* #ORM\Table(name="ad_base")
* #ORM\Entity(repositoryClass="AdBundle\Repository\AdBaseRepository")
* #ORM\HasLifecycleCallbacks()
* #ORM\InheritanceType("JOINED")
* #ORM\DiscriminatorColumn(name="discr", type="string")
* #ORM\DiscriminatorMap({
"flat" = "AdFlat"
* })
*/
abstract class AdBase
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* #var string
*
* #ORM\Column(name="author", type="string", length=255)
*/
private $author;
/**
* #ORM\ManyToOne(targetEntity="AdBundle\Entity\AdCategory")
*/
private $category;
/**
* #ORM\Column(type="string")
* #Assert\NotBlank(message="Field Location should not be blank")
*/
private $location;
/**
* #var string
*
* #ORM\Column(name="title", type="string", length=255)
* #Assert\NotBlank(message="Not specified Title")
*/
private $title;
/**
* #var string
*
* #ORM\Column(name="description", type="text", nullable=true)
* #Assert\NotBlank(message="Not specified Description")
*/
private $description;
/**
* #ORM\OneToMany(targetEntity="AdBundle\Entity\AdPhoto", mappedBy="ad")
*/
private $photos;
/**
* #ORM\Column(type="float")
* #Assert\NotBlank()
*/
private $price;
/**
* #ORM\ManyToOne(targetEntity="AdBundle\Entity\AdPriceType")
*/
private $priceType;
/**
* #var \DateTime
*
* #ORM\Column(name="createdAt", type="datetime")
*/
private $createdAt;
/**
* #var string
*
* #ORM\Column(name="updatedAt", type="datetime")
*/
private $updatedAt;
/**
* #var bool
*
* #ORM\Column(name="visible", type="boolean")
*/
private $visible = false;
/**
* #ORM\Column(type="boolean")
*/
private $active = true;
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set author
*
* #param string $author
*
* #return AdBase
*/
public function setAuthor($author)
{
$this->author = $author;
return $this;
}
/**
* Get author
*
* #return string
*/
public function getAuthor()
{
return $this->author;
}
/**
* #return mixed
*/
public function getCategory()
{
return $this->category;
}
/**
* #param mixed $category
*/
public function setCategory($category)
{
$this->category = $category;
}
/**
* #return mixed
*/
public function getLocation()
{
return $this->location;
}
/**
* #param mixed $location
*/
public function setLocation($location)
{
$this->location = $location;
}
/**
* Set title
*
* #param string $title
*
* #return AdBase
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* #return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set description
*
* #param string $description
*
* #return AdBase
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* #return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set photos
*
* #param string $photos
*
* #return AdBase
*/
public function setPhotos($photos)
{
$this->photos = $photos;
return $this;
}
/**
* Get photos
*
* #return string
*/
public function getPhotos()
{
return $this->photos;
}
/**
* #return mixed
*/
public function getPrice()
{
return $this->price;
}
/**
* #param mixed $price
*/
public function setPrice($price)
{
$this->price = $price;
}
/**
* #return mixed
*/
public function getPriceType()
{
return $this->priceType;
}
/**
* #param mixed $priceType
*/
public function setPriceType($priceType)
{
$this->priceType = $priceType;
}
/**
* Set createdAt
*
* #param \DateTime $createdAt
*
* #return AdBase
*/
public function setCreatedAt($createdAt)
{
$this->createdAt = $createdAt;
return $this;
}
/**
* Get createdAt
*
* #return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* Set updatedAt
*
* #param string $updatedAt
*
* #return AdBase
*/
public function setUpdatedAt($updatedAt)
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* Get updatedAt
*
* #return string
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
* Set visible
*
* #param boolean $visible
*
* #return AdBase
*/
public function setVisible($visible)
{
$this->visible = $visible;
return $this;
}
/**
* Get visible
*
* #return bool
*/
public function getVisible()
{
return $this->visible;
}
/**
* #return mixed
*/
public function getActive()
{
return $this->active;
}
/**
* #param mixed $active
*/
public function setActive($active)
{
$this->active = $active;
}
/**
* #ORM\PrePersist()
*/
public function prePersist()
{
$this->author = 'voodoo';
$this->createdAt = new \DateTime('now', new \DateTimeZone('UTC'));
$this->updatedAt = new \DateTime('now', new \DateTimeZone('UTC'));
$this->location = 'Donetsk';
}
/**
* #ORM\PreUpdate()
*/
public function preUpdate()
{
$this->updatedAt = new \DateTime('now', new \DateTimeZone('UTC'));
}
}
Extended entity:
<?php
namespace AdBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* AdFlat
*
* #ORM\Table(name="ad_flat")
* #ORM\Entity(repositoryClass="AdBundle\Repository\AdFlatRepository")
*/
class AdFlat extends AdBase
{
/**
* #var integer
*
* #ORM\Column(type="integer")
* #Assert\NotBlank(message="ad_flat.rooms.not_blank")
*/
private $rooms;
/**
* #var float
*
* #ORM\Column(name="square", type="float", nullable=true)
*/
private $square;
/**
* #var float
*
* #ORM\Column(name="liveSquare", type="float", nullable=true)
*/
private $liveSquare;
/**
* #var float
*
* #ORM\Column(type="float", nullable=true)
*/
private $kitchenSquare;
/**
* #var int
*
* #ORM\Column(name="floor", type="integer")
*/
private $floor;
/**
* #var int
*
* #ORM\Column(name="floors", type="integer")
*/
private $floors;
/**
* #var string
*
* #ORM\ManyToOne(targetEntity="AdBundle\Entity\AdWallType")
*/
private $wallType;
/**
* #ORM\ManyToOne(targetEntity="AdBundle\Entity\AdWCType")
*/
private $wcType;
/**
* #return mixed
*/
public function getRooms()
{
return $this->rooms;
}
/**
* #param mixed $rooms
*/
public function setRooms($rooms)
{
$this->rooms = $rooms;
}
/**
* Set square
*
* #param float $square
*
* #return AdFlat
*/
public function setSquare($square)
{
$this->square = $square;
return $this;
}
/**
* Get square
*
* #return float
*/
public function getSquare()
{
return $this->square;
}
/**
* Set liveSquare
*
* #param float $liveSquare
*
* #return AdFlat
*/
public function setLiveSquare($liveSquare)
{
$this->liveSquare = $liveSquare;
return $this;
}
/**
* Get liveSquare
*
* #return float
*/
public function getLiveSquare()
{
return $this->liveSquare;
}
/**
* #return float
*/
public function getKitchenSquare()
{
return $this->kitchenSquare;
}
/**
* #param float $kitchenSquare
*/
public function setKitchenSquare($kitchenSquare)
{
$this->kitchenSquare = $kitchenSquare;
}
/**
* Set floor
*
* #param integer $floor
*
* #return AdFlat
*/
public function setFloor($floor)
{
$this->floor = $floor;
return $this;
}
/**
* Get floor
*
* #return int
*/
public function getFloor()
{
return $this->floor;
}
/**
* Set floors
*
* #param integer $floors
*
* #return AdFlat
*/
public function setFloors($floors)
{
$this->floors = $floors;
return $this;
}
/**
* Get floors
*
* #return int
*/
public function getFloors()
{
return $this->floors;
}
/**
* Set wallType
*
* #param string $wallType
*
* #return AdFlat
*/
public function setWallType($wallType)
{
$this->wallType = $wallType;
return $this;
}
/**
* Get wallType
*
* #return string
*/
public function getWallType()
{
return $this->wallType;
}
/**
* Set wcType
*
* #param string $wcType
*
* #return AdFlat
*/
public function setWcType($wcType)
{
$this->wcType = $wcType;
return $this;
}
/**
* Get wcType
*
* #return string
*/
public function getWcType()
{
return $this->wcType;
}
}
In controller:
public function editAction(Request $request)
{
$adId = $request->get('id');
if (!$adId) {
return $this->renderError('Unknown Ad');
}
$adEntity = $this->getDoctrine()->getRepository('AdBundle:AdBase')->find($adId);
if (null === $adEntity) {
return $this->renderError('Unknown Ad');
}
$reflection = new \ReflectionClass($adEntity);
$adForm = $this->getForm($reflection->getShortName());
$form = $this->createForm($adForm, $adEntity);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($adEntity);
$em->flush();
return $this->redirectToRoute('ad_bundle_ad_view', array(
'id' => $adEntity->getId()
));
}
return $this->render('AdBundle:Ad:edit-ad-flat.html.twig', array(
'form' => $form->createView()
));
}
private function renderError($message = '')
{
return $this->render('::error.html.twig', array(
'error' => $message
));
}
private function getEntity($className)
{
$entityName = 'AdBundle\Entity\\' . $className;
return new $entityName();
}
private function getForm($className)
{
$formName = 'AdBundle\Form\Type\\' . $className . 'Type';
return new $formName();
}

The error message simply states that you are missing a way to set the entity's $id property. It doesn't tell you anything about the class not extending the base class. However, your base class only defines a getter method for the $id property but no setter method.

Doctrine Entities work as POPOs (Plain Old PHP Objects). To achieve extending correctly you need to work with the MappedSuperClass here is an example

Related

How annotation #groups for the sluggable column

I'm working in symfony 3.3:
I need to add the #Groups annotation to the slug field (created using ORMBehaviors\Sluggable\Sluggable) so I can pass this field through other entities that I will specify in the Groups.
How can I do this?
this is the entity 'foo':
/**
* #var int
*
* #ORM\Id
* #ORM\GeneratedValue
* #ORM\Column(type="integer")
*
* #Groups({"advertisingSpace"})
*/
private $id;
/**
* #var string
*
* #ORM\Column(type="string", length=4)
*
* #Groups({"advertisingSpace"})
*/
private $code;
/**
* #var string
*
* #ORM\Column(type="string", length=255)
*
* #Groups({"advertisingSpace"})
*/
private $description;
/**
* #Vich\UploadableField(mapping="advertisingspacecategory_icon", fileNameProperty="icon")
*
* #var File
*/
private $iconFile;
/**
* #var string
*
* #ORM\Column(type="string", length=255)
*
* #Groups({"advertisingSpace"})
*/
private $icon;
/**
* #var array
*
* #ORM\OneToMany(
* targetEntity="AppBundle\Entity\AdvertisingSpace",
* mappedBy="category"
* )
*/
private $advertisingSpaces;
/**
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* #return string
*/
public function getIcon()
{
return $this->icon;
}
/**
* #param string $icon
*
* #return AdvertisingSpaceCategory
*/
public function setIcon($icon)
{
$this->icon = $icon;
return $this;
}
/**
* #param File|\Symfony\Component\HttpFoundation\File\UploadedFile $iconFile
*
* #return AdvertisingSpaceCategory
*/
public function setIconFile(File $iconFile = null)
{
$this->iconFile = $iconFile;
if ($iconFile) {
$this->updatedAt = new \DateTimeImmutable();
}
return $this;
}
/**
* #return File|null
*/
public function getIconFile()
{
return $this->iconFile;
}
/**
* #param int $id
*
* #return AdvertisingSpaceCategory
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* #return string
*/
public function getCode()
{
return $this->code;
}
/**
* #param string $code
*
* #return AdvertisingSpaceCategory
*/
public function setCode($code)
{
$this->code = $code;
return $this;
}
/**
* #return array
*/
public function getAdvertisingSpaces()
{
return $this->advertisingSpaces;
}
/**
* #param array $advertisingSpaces
*
* #return AdvertisingSpaceCategory
*/
public function setAdvertisingSpaces($advertisingSpaces)
{
$this->advertisingSpaces = $advertisingSpaces;
return $this;
}
/**
* #return string
*/
public function getDescription()
{
return $this->description;
}
/**
* #param string $description
*
* #return $this
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* #return array
*/
public function getSluggableFields()
{
return [ 'slug' ];
}
/**
* #param string $values
*
* #return string
*/
public function generateSlugValue($values)
{
return implode('-', $values);
}
not having the private slug declaration as I can attribute the #groups annotation to?
You should install the JMS Serializer Bundle and use the #VirtualProperty annotation on your own getSlug() method like the following
/**
* #VirtualProperty
* #Groups({"advertisingSpace"})
*/
public function getSlug()
{
return parent::getSlug();
}
I solved it anyway by creating a new string variable (Eg "SlugName"):
/**
* #var string
*
* #Groups({"advertisingSpace"})
*/
private $slugName;
where I inserted the Groups annotation and which returns the original 'slug' field from its getter:
/**
* # return string
*/
public function getSlugName(): string
{
return $this->slug;
}

Sonata Admin Bundle Many-to-Many relationship not saving foreign ID

Here is my problem. I have two entities with a Many-To-Many relationship and would like to insert in a field multiple information.
I use sonata admin for administration, and here is my code:
Notification Class:
<?php
namespace App\BlogBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Notification
*
* #ORM\Table(name="notification")
* #ORM\Entity
*/
class Notification {
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="message", type="string", length=255)
*/
private $message;
/**
* #ORM\ManyToMany(targetEntity="Etudiant",mappedBy="notification")
*/
private $etudiant;
/**
* Get id
*
* #return integer
*/
public function getId() {
return $this->id;
}
/**
* Set message
*
* #param string $message
* #return Notification
*/
public function setMessage($message) {
$this->message = $message;
return $this;
}
/**
* Get message
*
* #return string
*/
public function getMessage() {
return $this->message;
}
public function __toString() {
return $this->message;
}
public function __construct() {
$this->etudiant = new \Doctrine\Common\Collections\ArrayCollection();
}
public function setEtudiant($etudiant) {
if (count($etudiant) > 0) {
foreach ($etudiant as $i) {
$this->addEtudiant($i);
}
}
return $this;
}
/**
* Add etudiant
*
* #param \App\BlogBundle\Entity\Etudiant $etudiant
* #return Notification
*/
public function addEtudiant(\App\BlogBundle\Entity\Etudiant $etudiant)
{
$this->etudiant[] = $etudiant;
return $this;
}
/**
* Remove etudiant
*
* #param \App\BlogBundle\Entity\Etudiant $etudiant
*/
public function removeEtudiant(\App\BlogBundle\Entity\Etudiant $etudiant)
{
$this->etudiant->removeElement($etudiant);
}
/**
* Get etudiant
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getEtudiant()
{
return $this->etudiant;
}
}
Etudiant Class:
<?php
namespace App\BlogBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Etudiant
*
* #ORM\Table(name="etudiant")
* #ORM\Entity
*/
class Etudiant{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="nom", type="string", length=255)
*/
private $nom;
/**
* #var string
*
* #ORM\Column(name="prenom", type="string", length=255)
*/
private $prenom;
/**
* #var \DateTime
*
* #ORM\Column(name="date_naissance", type="datetime")
*/
private $dateNaissance;
/**
* #var string
*
* #ORM\Column(name="adresse", type="text")
*/
private $adresse;
/**
* #var string
*
* #ORM\Column(name="email", type="string", length=255)
*/
private $email;
/**
* #var int
*
* #ORM\Column(name="telephone", type="integer")
*/
private $telephone;
/**
* #var string
*
* #ORM\Column(name="num_inscription", type="string", length=255)
*/
private $numInscription;
/**
* #var \DateTime
*
* #ORM\Column(name="date_inscription", type="datetime")
*/
private $dateInscription;
/**
* #var int
*
* #ORM\Column(name="frais_scolarite", type="integer")
*/
private $fraisScolarite;
/**
* #ORM\ManyToMany(targetEntity="Notification",inversedBy="etudiant")
*#ORM\JoinColumn(name="user_notificaiton")
*/
private $notification;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set nom
*
* #param string $nom
* #return Etudiant
*/
public function setNom($nom)
{
$this->nom = $nom;
return $this;
}
/**
* Get nom
*
* #return string
*/
public function getNom()
{
return $this->nom;
}
/**
* Set prenom
*
* #param string $prenom
* #return Etudiant
*/
public function setPrenom($prenom)
{
$this->prenom = $prenom;
return $this;
}
/**
* Get prenom
*
* #return string
*/
public function getPrenom()
{
return $this->prenom;
}
/**
* Set dateNaissance
*
* #param \DateTime $dateNaissance
* #return Etudiant
*/
public function setDateNaissance($dateNaissance)
{
$this->dateNaissance = $dateNaissance;
return $this;
}
/**
* Get dateNaissance
*
* #return \DateTime
*/
public function getDateNaissance()
{
return $this->dateNaissance;
}
/**
* Set adresse
*
* #param string $adresse
* #return Etudiant
*/
public function setAdresse($adresse)
{
$this->adresse = $adresse;
return $this;
}
/**
* Get adresse
*
* #return string
*/
public function getAdresse()
{
return $this->adresse;
}
/**
* Set email
*
* #param string $email
* #return Etudiant
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get email
*
* #return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set telephone
*
* #param integer $telephone
* #return Etudiant
*/
public function setTelephone($telephone)
{
$this->telephone = $telephone;
return $this;
}
/**
* Get telephone
*
* #return integer
*/
public function getTelephone()
{
return $this->telephone;
}
/**
* Set numInscription
*
* #param string $numInscription
* #return Etudiant
*/
public function setNumInscription($numInscription)
{
$this->numInscription = $numInscription;
return $this;
}
/**
* Get numInscription
*
* #return string
*/
public function getNumInscription()
{
return $this->numInscription;
}
/**
* Set dateInscription
*
* #param \DateTime $dateInscription
* #return Etudiant
*/
public function setDateInscription($dateInscription)
{
$this->dateInscription = $dateInscription;
return $this;
}
/**
* Get dateInscription
*
* #return \DateTime
*/
public function getDateInscription()
{
return $this->dateInscription;
}
/**
* Set fraisScolarite
*
* #param integer $fraisScolarite
* #return Etudiant
*/
public function setFraisScolarite($fraisScolarite)
{
$this->fraisScolarite = $fraisScolarite;
return $this;
}
/**
* Get fraisScolarite
*
* #return integer
*/
public function getFraisScolarite()
{
return $this->fraisScolarite;
}
public function __toString() {
return $this->nom;
}
public function __construct() {
$this->notification = new \Doctrine\Common\Collections\ArrayCollection();
}
function setNotification($notification) {
if (count($notification) > 0) {
foreach ($notification as $i) {
$this->addEtudiant($i);
}
}
return $this;
}
/**
* Add notification
*
* #param \App\BlogBundle\Entity\Notification $notification
* #return Etudiant
*/
public function addNotification(\App\BlogBundle\Entity\Notification $notification)
{
$this->notification[] = $notification;
return $this;
}
/**
* Remove notification
*
* #param \App\BlogBundle\Entity\Notification $notification
*/
public function removeNotification(\App\BlogBundle\Entity\Notification $notification)
{
$this->notification->removeElement($notification);
}
/**
* Get notification
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getNotification()
{
return $this->notification;
}
}
Finally My NotificationAdmin:
<?php
namespace App\BlogBundle\Admin;
use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Show\ShowMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
class NotificationAdmin extends Admin {
// Fields to be shown on create/edit forms
protected function configureFormFields(FormMapper $formMapper) {
$formMapper
->add('message', 'text')
->add('etudiant', 'sonata_type_model', array(
'required' => false,
'multiple' => true
))
;
}
// Fields to be shown on filter forms
protected function configureDatagridFilters(DatagridMapper $datagridMapper) {
$datagridMapper
->add('message')
->add('etudiant')
;
}
// Fields to be shown on lists
protected function configureListFields(ListMapper $listMapper) {
$listMapper
->addIdentifier('message')
->add('etudiant')
;
}
// Fields to be shown on show action
protected function configureShowFields(ShowMapper $showMapper) {
$showMapper
->add('id')
->add('nom')
;
}
public function prePersist($notification){
$this->preUpdate($notification);
}
public function preUpdate($notification){
$notification->setEtudiant($notification);
}
public function getBatchActions() {
// retrieve the default batch actions (currently only delete)
$actions = parent::getBatchActions();
if (
$this->hasRoute('edit') && $this->isGranted('EDIT') &&
$this->hasRoute('delete') && $this->isGranted('DELETE')
) {
$actions['merge'] = array(
'label' => 'action_merge',
'translation_domain' => 'SonataAdminBundle',
'ask_confirmation' => true
);
}
return $actions;
}
}
And there is nothing in my table "etudiant_notification".
Please make the following changes (bold lines) to your code:
Notification.php
/**
* Add etudiant
*
* #param \App\BlogBundle\Entity\Etudiant $etudiant
* #return Notification
*/
public function addEtudiant(\App\BlogBundle\Entity\Etudiant $etudiant)
{
$etudiant->addNotification($this);
$this->etudiant[] = $etudiant;
return $this;
}
Etudiant.php
/**
* Add notification
*
* #param \App\BlogBundle\Entity\Notification $notification
* #return Etudiant
*/
public function addNotification(\App\BlogBundle\Entity\Notification $notification)
{
$notification->addEtudiant($this);
$this->notification[] = $notification;
return $this;
}
and check what happens. No guarantee, but you can give it a try. Bonne chance!

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.

Doctrine 2 perform insert, update on entity locally but fails without error on staging

I have an entity called DoerTrip
namespace Application\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Doer Trip
*
* #ORM\Table(name="doer_trip")
* #ORM\Entity
*/
class DoerTrip extends AbstractEntity
{
const STATUS_PUBLISHED = 1;
const STATUS_UNPUBLISHED = 0;
/**
* #var integer
*
* #ORM\Column(name="`id`", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
protected $id;
/**
* #var \Application\Entity\Doer
*
* #ORM\ManyToOne(targetEntity="Doer")
* #ORM\JoinColumn(name="`doer_id`", referencedColumnName="id")
*/
protected $doer; // inversedBy="trips"
/**
* #var \Application\Entity\Trip
*
* #ORM\ManyToOne(targetEntity="Trip")
* #ORM\JoinColumn(name="`trip_id`", referencedColumnName="id")
*/
protected $trip; //inversedBy="doers"
/**
* #var bool
*
* #ORM\Column(name="`published`", type="boolean")
*/
protected $published;
/**
* #var string
*
* #ORM\Column(name="`comment`", type="text")
*/
protected $comment;
/**
* #var integer
*
* #ORM\Column(name="`target_sum`", type="integer")
*/
protected $targetSum;
public function __construct()
{
$this->published = false;
}
/**
* #param string $comment
* #return $this
*/
public function setComment($comment)
{
$this->comment = $comment;
return $this;
}
/**
* #return string
*/
public function getComment()
{
return $this->comment;
}
/**
* #param \Application\Entity\Doer $doer
* #return $this
*/
public function setDoer(Doer $doer)
{
$this->doer = $doer;
return $this;
}
/**
* #return \Application\Entity\Doer
*/
public function getDoer()
{
return $this->doer;
}
/**
* #param int $id
* #return $this
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* #param boolean $published
* #return $this
*/
public function setPublished($published)
{
$this->published = $published;
return $this;
}
/**
* #return boolean
*/
public function getPublished()
{
return $this->published;
}
/**
* #param \Application\Entity\Trip $trip
* #return $this
*/
public function setTrip(Trip $trip)
{
$this->trip = $trip;
return $this;
}
/**
* #return \Application\Entity\Trip
*/
public function getTrip()
{
return $this->trip;
}
/**
* #param int $targetSum
* #return $this
*/
public function setTargetSum($targetSum)
{
$this->targetSum = $targetSum;
return $this;
}
/**
* #return int
*/
public function getTargetSum()
{
return (null !== $this->targetSum) ? $this->targetSum : $this->getTrip()->getTargetAmount();
}
}
here Trip Entity:
namespace Application\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Zend\Validator\IsInstanceOf;
/**
* Trip
*
* #ORM\Table(name="trip")
* #ORM\Entity
*/
class Trip extends AbstractEntity
{
const STATUS_ACTIVE = 'active';
const STATUS_INACTIVE = 'inactive';
const STATUS_BANNED = 'banned';
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255)
*/
protected $name;
/**
* #var Collection
*
* #ORM\ManyToMany(targetEntity="Media", cascade={"remove"}, orphanRemoval=true)
* #ORM\JoinTable(name="trip_media",
* joinColumns={#ORM\JoinColumn(name="trip_id", referencedColumnName="id")},
* inverseJoinColumns={#ORM\JoinColumn(name="file_id", referencedColumnName="id", unique=true)}
* )
*/
protected $media;
/**
* #var \Application\Entity\Media
*
* #ORM\OneToOne(targetEntity="Media", mappedBy="trip", cascade={"persist", "remove"})
* #ORM\JoinColumn(name="main_media_id", referencedColumnName="id")
*/
protected $mainMedia;
/**
* #var string
*
* #ORM\Column(name="api_key", type="string", length=255)
*/
protected $apiKey;
/**
* #var string
*
* #ORM\Column(name="country", type="string", length=255, nullable=true)
*/
protected $country;
/**
* #var \DateTime
*
* #ORM\Column(name="departure_date", type="date", nullable=true)
*/
protected $departureDate;
/**
* #var \DateTime
*
* #ORM\Column(name="due_date", type="date", nullable=true)
*/
protected $dueDate;
/**
* #var \DateTime
*
* #ORM\Column(name="return_date", type="date", nullable=true)
*/
protected $returnDate;
/**
* #var string
*
* #ORM\Column(name="description", type="text", nullable=true)
*/
protected $description;
/**
* #var string
*
* #ORM\Column(name="target_amount", type="integer")
*/
protected $targetAmount;
/**
* #var Collection
*
* #ORM\OneToMany(targetEntity="DoerTrip", mappedBy="trip", cascade={"persist","remove"}, orphanRemoval=true)
*/
protected $doers;
/**
* #var Organization
*
* #ORM\ManyToOne(targetEntity="Organization", inversedBy="trips")
* #ORM\JoinColumn(name="organization_id", referencedColumnName="id")
*/
protected $organization;
/**
* #var Cause
*
* #ORM\OneToOne(targetEntity="Cause", inversedBy="trips")
* #ORM\JoinColumn(name="cause_id", referencedColumnName="id", onDelete="SET NULL")
*/
protected $cause;
/**
* #var integer
*
* #ORM\Column(name="status", type="string" ,columnDefinition="ENUM('active', 'inactive', 'banned')")
*/
protected $status;
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
protected $id;
/**
* #var Transaction
*
* #ORM\OneToMany(targetEntity="Transaction", mappedBy="trip", cascade={"remove"}, orphanRemoval=true)
*/
protected $transactions;
/**
* #param Organization $organization
* #return $this
*/
public function setOrganization(Organization $organization)
{
$this->organization = $organization;
return $this;
}
/**
* #return Organization
*/
public function getOrganization()
{
return $this->organization;
}
public function __construct()
{
$this->doers = new ArrayCollection();
$this->media = new ArrayCollection();
$this->status = self::STATUS_ACTIVE;
$this->transactions = new ArrayCollection();
$this->targetAmount = 0;
$this->description = '';
}
/**
* #param string $apiKey
* #return $this
*/
public function setApiKey($apiKey)
{
$this->apiKey = $apiKey;
return $this;
}
/**
* #return string
*/
public function getApiKey()
{
return $this->apiKey;
}
/**
* #param string $country
* #return $this
*/
public function setCountry($country)
{
$this->country = $country;
return $this;
}
/**
* #return string
*/
public function getCountry()
{
return $this->country;
}
/**
* #param string $description
* #return $this
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* #return string
*/
public function getDescription()
{
return $this->description;
}
/**
* #param \DateTime $dueDate
* #return $this
*/
public function setDueDate(\DateTime $dueDate)
{
$this->dueDate = $dueDate;
return $this;
}
/**
* #return \DateTime
*/
public function getDueDate()
{
return $this->dueDate;
}
/**
* #param int $id
* #return $this
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* #param \DateTime $departureDate
* #return $this
*/
public function setDepartureDate(\DateTime $departureDate)
{
$this->departureDate = $departureDate;
return $this;
}
/**
* #return \DateTime
*/
public function getDepartureDate()
{
return $this->departureDate;
}
/**
* #param string $targetAmount
* #return $this
*/
public function setTargetAmount($targetAmount)
{
$this->targetAmount = $targetAmount;
return $this;
}
/**
* #return string
*/
public function getTargetAmount()
{
return $this->targetAmount;
}
/**
* #param string $name
* #return $this
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* #param int $status
* #return $this
*/
public function setStatus($status)
{
$this->status = $status;
return $this;
}
/**
* #return int
*/
public function getStatus()
{
return $this->status;
}
/**
* #param \Application\Entity\Cause $cause
* #return $this
*/
public function setCause($cause)
{
$this->cause = $cause;
return $this;
}
/**
* #return \Application\Entity\Cause
*/
public function getCause()
{
return $this->cause;
}
/**
* #param \Doctrine\Common\Collections\Collection $media
* #return $this
*/
public function setMedia($media)
{
$this->media = $media;
return $this;
}
/**
* #return \Doctrine\Common\Collections\Collection
*/
public function getMedia()
{
return $this->media;
}
/**
* #param \Application\Entity\DoerTrip $doer
* #return $this
*/
public function addDoer(DoerTrip $doer)
{
$this->doers->add($doer);
$doer->setTrip($this);
return $this;
}
/**
* #param Collection $doers
* #return $this
*/
public function setDoers(Collection $doers)
{
$this->doers = $doers;
return $this;
}
/**
* #return Collection
*/
public function getDoers()
{
return $this->doers;
}
/**
* #param \Application\Entity\DoerTrip $doer
* #return $this
*/
public function removeDoer(DoerTrip $doer)
{
$this->doers->removeElement($doer);
return $this;
}
/**
* #param \Doctrine\Common\Collections\Collection $transactions
* #return $this
*/
public function setTransactions($transactions)
{
$this->transactions = $transactions;
return $this;
}
/**
* #return \Doctrine\Common\Collections\Collection
*/
public function getTransactions()
{
return $this->transactions;
}
/**
* #param array $data
* #return $this
*/
public function populate(array $data)
{
if (!empty($data['departureDate']) && !$data['departureDate'] instanceof \DateTime) {
$data['departureDate'] = new \DateTime($data['departureDate']);
}
if (!empty($data['dueDate']) && !$data['dueDate'] instanceof \DateTime) {
$data['dueDate'] = new \DateTime($data['dueDate']);
}
if (!empty($data['returnDate']) && !$data['returnDate'] instanceof \DateTime) {
$data['returnDate'] = new \DateTime($data['returnDate']);
}
parent::populate($data);
return $this;
}
/**
* #param \DateTime $returnDate
* #return $this
*/
public function setReturnDate(\DateTime $returnDate)
{
$this->returnDate = $returnDate;
return $this;
}
/**
* #return \DateTime
*/
public function getReturnDate()
{
return $this->returnDate;
}
/**
* #param \Application\Entity\Media $mainMedia
* #return $this
*/
public function setMainMedia($mainMedia)
{
$this->mainMedia = $mainMedia;
return $this;
}
/**
* #return \Application\Entity\Media
*/
public function getMainMedia()
{
return $this->mainMedia;
}
/**
* #param Media $media
* #return bool
*/
public function hasMedia(Media $media)
{
return $this->getMedia()->contains($media);
}
/**
* #param \Application\Entity\Media $media
* #return $this
*/
public function addMedia(Media $media)
{
$this->media->add($media);
return $this;
}
/**
* #param \Application\Entity\Media $media
* #return $this
*/
public function removeMedia(Media $media)
{
$this->media->removeElement($media);
return $this;
}
}
Here is Doer Entity
namespace Application\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Zend\Validator\IsInstanceOf;
/**
* Trip
*
* #ORM\Table(name="trip")
* #ORM\Entity
*/
class Trip extends AbstractEntity
{
const STATUS_ACTIVE = 'active';
const STATUS_INACTIVE = 'inactive';
const STATUS_BANNED = 'banned';
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255)
*/
protected $name;
/**
* #var Collection
*
* #ORM\ManyToMany(targetEntity="Media", cascade={"remove"}, orphanRemoval=true)
* #ORM\JoinTable(name="trip_media",
* joinColumns={#ORM\JoinColumn(name="trip_id", referencedColumnName="id")},
* inverseJoinColumns={#ORM\JoinColumn(name="file_id", referencedColumnName="id", unique=true)}
* )
*/
protected $media;
/**
* #var \Application\Entity\Media
*
* #ORM\OneToOne(targetEntity="Media", mappedBy="trip", cascade={"persist", "remove"})
* #ORM\JoinColumn(name="main_media_id", referencedColumnName="id")
*/
protected $mainMedia;
/**
* #var string
*
* #ORM\Column(name="api_key", type="string", length=255)
*/
protected $apiKey;
/**
* #var string
*
* #ORM\Column(name="country", type="string", length=255, nullable=true)
*/
protected $country;
/**
* #var \DateTime
*
* #ORM\Column(name="departure_date", type="date", nullable=true)
*/
protected $departureDate;
/**
* #var \DateTime
*
* #ORM\Column(name="due_date", type="date", nullable=true)
*/
protected $dueDate;
/**
* #var \DateTime
*
* #ORM\Column(name="return_date", type="date", nullable=true)
*/
protected $returnDate;
/**
* #var string
*
* #ORM\Column(name="description", type="text", nullable=true)
*/
protected $description;
/**
* #var string
*
* #ORM\Column(name="target_amount", type="integer")
*/
protected $targetAmount;
/**
* #var Collection
*
* #ORM\OneToMany(targetEntity="DoerTrip", mappedBy="trip", cascade={"persist","remove"}, orphanRemoval=true)
*/
protected $doers;
/**
* #var Organization
*
* #ORM\ManyToOne(targetEntity="Organization", inversedBy="trips")
* #ORM\JoinColumn(name="organization_id", referencedColumnName="id")
*/
protected $organization;
/**
* #var Cause
*
* #ORM\OneToOne(targetEntity="Cause", inversedBy="trips")
* #ORM\JoinColumn(name="cause_id", referencedColumnName="id", onDelete="SET NULL")
*/
protected $cause;
/**
* #var integer
*
* #ORM\Column(name="status", type="string" ,columnDefinition="ENUM('active', 'inactive', 'banned')")
*/
protected $status;
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
protected $id;
/**
* #var Transaction
*
* #ORM\OneToMany(targetEntity="Transaction", mappedBy="trip", cascade={"remove"}, orphanRemoval=true)
*/
protected $transactions;
/**
* #param Organization $organization
* #return $this
*/
public function setOrganization(Organization $organization)
{
$this->organization = $organization;
return $this;
}
/**
* #return Organization
*/
public function getOrganization()
{
return $this->organization;
}
public function __construct()
{
$this->doers = new ArrayCollection();
$this->media = new ArrayCollection();
$this->status = self::STATUS_ACTIVE;
$this->transactions = new ArrayCollection();
$this->targetAmount = 0;
$this->description = '';
}
/**
* #param string $apiKey
* #return $this
*/
public function setApiKey($apiKey)
{
$this->apiKey = $apiKey;
return $this;
}
/**
* #return string
*/
public function getApiKey()
{
return $this->apiKey;
}
/**
* #param string $country
* #return $this
*/
public function setCountry($country)
{
$this->country = $country;
return $this;
}
/**
* #return string
*/
public function getCountry()
{
return $this->country;
}
/**
* #param string $description
* #return $this
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* #return string
*/
public function getDescription()
{
return $this->description;
}
/**
* #param \DateTime $dueDate
* #return $this
*/
public function setDueDate(\DateTime $dueDate)
{
$this->dueDate = $dueDate;
return $this;
}
/**
* #return \DateTime
*/
public function getDueDate()
{
return $this->dueDate;
}
/**
* #param int $id
* #return $this
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* #param \DateTime $departureDate
* #return $this
*/
public function setDepartureDate(\DateTime $departureDate)
{
$this->departureDate = $departureDate;
return $this;
}
/**
* #return \DateTime
*/
public function getDepartureDate()
{
return $this->departureDate;
}
/**
* #param string $targetAmount
* #return $this
*/
public function setTargetAmount($targetAmount)
{
$this->targetAmount = $targetAmount;
return $this;
}
/**
* #return string
*/
public function getTargetAmount()
{
return $this->targetAmount;
}
/**
* #param string $name
* #return $this
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* #param int $status
* #return $this
*/
public function setStatus($status)
{
$this->status = $status;
return $this;
}
/**
* #return int
*/
public function getStatus()
{
return $this->status;
}
/**
* #param \Application\Entity\Cause $cause
* #return $this
*/
public function setCause($cause)
{
$this->cause = $cause;
return $this;
}
/**
* #return \Application\Entity\Cause
*/
public function getCause()
{
return $this->cause;
}
/**
* #param \Doctrine\Common\Collections\Collection $media
* #return $this
*/
public function setMedia($media)
{
$this->media = $media;
return $this;
}
/**
* #return \Doctrine\Common\Collections\Collection
*/
public function getMedia()
{
return $this->media;
}
/**
* #param \Application\Entity\DoerTrip $doer
* #return $this
*/
public function addDoer(DoerTrip $doer)
{
$this->doers->add($doer);
$doer->setTrip($this);
return $this;
}
/**
* #param Collection $doers
* #return $this
*/
public function setDoers(Collection $doers)
{
$this->doers = $doers;
return $this;
}
/**
* #return Collection
*/
public function getDoers()
{
return $this->doers;
}
/**
* #param \Application\Entity\DoerTrip $doer
* #return $this
*/
public function removeDoer(DoerTrip $doer)
{
$this->doers->removeElement($doer);
return $this;
}
/**
* #param \Doctrine\Common\Collections\Collection $transactions
* #return $this
*/
public function setTransactions($transactions)
{
$this->transactions = $transactions;
return $this;
}
/**
* #return \Doctrine\Common\Collections\Collection
*/
public function getTransactions()
{
return $this->transactions;
}
/**
* #param array $data
* #return $this
*/
public function populate(array $data)
{
if (!empty($data['departureDate']) && !$data['departureDate'] instanceof \DateTime) {
$data['departureDate'] = new \DateTime($data['departureDate']);
}
if (!empty($data['dueDate']) && !$data['dueDate'] instanceof \DateTime) {
$data['dueDate'] = new \DateTime($data['dueDate']);
}
if (!empty($data['returnDate']) && !$data['returnDate'] instanceof \DateTime) {
$data['returnDate'] = new \DateTime($data['returnDate']);
}
parent::populate($data);
return $this;
}
/**
* #param \DateTime $returnDate
* #return $this
*/
public function setReturnDate(\DateTime $returnDate)
{
$this->returnDate = $returnDate;
return $this;
}
/**
* #return \DateTime
*/
public function getReturnDate()
{
return $this->returnDate;
}
/**
* #param \Application\Entity\Media $mainMedia
* #return $this
*/
public function setMainMedia($mainMedia)
{
$this->mainMedia = $mainMedia;
return $this;
}
/**
* #return \Application\Entity\Media
*/
public function getMainMedia()
{
return $this->mainMedia;
}
/**
* #param Media $media
* #return bool
*/
public function hasMedia(Media $media)
{
return $this->getMedia()->contains($media);
}
/**
* #param \Application\Entity\Media $media
* #return $this
*/
public function addMedia(Media $media)
{
$this->media->add($media);
return $this;
}
/**
* #param \Application\Entity\Media $media
* #return $this
*/
public function removeMedia(Media $media)
{
$this->media->removeElement($media);
return $this;
}
}
I perform this sample of code:
$doerTrip = new DoerTrip();
$doerTrip->setDoer($doer)->setTrip($trip);
$em->persist($doerTrip);
$em->flush();
locally it works (on Windows). But on staging (Ubuntu) new record is not created and I don't get any errors. Update of the entity DoerTrip on staging doesn't work too.
If I perform insert with the help of connection something like this
$stmt = $conn->prepare('INSERT INTO doer_trip (...) VALUES (?,?,?,?,?)');
$stmt->bindParam(1, $param);
...
everything works fine.
When using ORM in SQL Logger I can see
START TRANSACTION;
INSERT INTO doer_trip (...) VALUES (?,?,?,?,?)
COMMIT;
but new record is not created on staging.
locally everything works fine.
I don't know maybe it depends on MySQL configuration.
I have no idea.
Here my doer_trip table
CREATE TABLE `doer_trip` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`doer_id` INT(11) NOT NULL,
`trip_id` INT(11) UNSIGNED NOT NULL,
`published` INT(1) UNSIGNED NOT NULL DEFAULT '0',
`comment` TEXT NULL,
`target_sum` INT(10) UNSIGNED NULL DEFAULT NULL,
PRIMARY KEY (`id`),
INDEX `doer_id` (`doer_id`),
INDEX `trip_id` (`trip_id`),
UNIQUE INDEX `doer_iduniq` (`doer_id`, `trip_id`),
CONSTRAINT `FK_doer_trip_trip` FOREIGN KEY (`trip_id`) REFERENCES `trip` (`id`),
CONSTRAINT `FK_doer_trip_doer` FOREIGN KEY (`doer_id`) REFERENCES `doer` (`id`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
ROW_FORMAT=DEFAULT
AUTO_INCREMENT=41
The problem was in
/**
* #var bool
*
* #ORM\Column(name="`published`", type="boolean")
*/
protected $published;
If I set type to integer like this
/**
* #var integer
*
* #ORM\Column(name="`published`", type="integer")
*/
protected $published;
Everything work fine. But why it works fine on my local environment???

AbstractType Proxies\__CG__\Far\MT\AccountBundle\Entity\Account could not be converted to int in

class Accounts extends AbstractType
{
private $em;
private $accountrepo = null;
private $choices = array();
public function __construct()
{
}
public function setAccountRepository($repo)
{
$this->accountrepo = $repo;
return $this;
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults([
'choices' => $this->getChoices(),
'attr' => [
'data-dojo-type' => 'dijit/form/FilteringSelect',
],
'data_class' => 'Far\MT\AccountBundle\Entity\Account'
]);
}
public function getParent()
{
return 'choice';
}
public function getName()
{
return 'Accounts';
}
public function getChoices()
{
if ( count($this->choices) > 0 ) {
return $this->choices;
}
$this->choices[0] = "";
foreach ($this->accountrepo->findAll() as $account) {
$this->choices[$account->getId()] = $account->getName() . " (" .
$account->getCurrency().") ";
}
return $this->choices;
}
}
Using the code above I get the error:
Notice: Object of class
Proxies__CG__\Far\MT\AccountBundle\Entity\Account could not be
converted to int in
/workspace/tools/vendorsymfony2/symfony/symfony/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.php
line 457
This only happens when I edit the record, I'm using this Type has a ChoiceList type in order to have the db values filtered and placed on the "combobox".
Any sugestions on what I can be doing wrong?
EDIT
use Doctrine\ORM\Mapping as ORM;
/**
* Movement
*
* #ORM\Entity(repositoryClass="Far\MT\AccountBundle\Entity\MovementRepository")
* #ORM\Table(name="movement")
*/
class Movement
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var \Date
*
* #ORM\Column(name="date", type="date")
*/
private $date;
/**
* #var string
*
* #ORM\ManyToOne(targetEntity="MovementType")
* #ORM\JoinColumn(name="movementtype", referencedColumnName="id", unique=false)
*/
private $Type;
/**
* #var float
*
* #ORM\Column(name="value", type="float")
*/
private $value;
/**
* #var Account
*
* #ORM\ManyToOne(targetEntity="Account", cascade={"persist"})
* #ORM\JoinColumn(name="fromaccount", referencedColumnName="id", unique=false)
*/
private $fromAccount;
/**
* #var Account
*
* #ORM\ManyToOne(targetEntity="Account", cascade={"persist"})
* #ORM\JoinColumn(name="toaccount", referencedColumnName="id", unique=false)
*/
private $toAccount;
/**
* #var string
*
* #ORM\ManyToOne(targetEntity="ExpenseType", cascade={"persist"})
* #ORM\JoinColumn(name="expensetype", referencedColumnName="id",
* nullable=true, unique=false)
*/
private $ExpenseType;
/**
* #var string
*
* #ORM\ManyToOne(targetEntity="Holder", cascade={"persist"})
* #ORM\JoinColumn(name="holder", referencedColumnName="id", unique=false)
*/
private $orderHolder;
/**
* #var string
*
* #ORM\Column(name="description", type="string", length=254)
*/
private $description;
/**
* #var float
*
* #ORM\Column(name="xrate", type="float", nullable=true)
*/
private $xrate = null;
public function getDescription()
{
return $this->description;
}
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set Account
*
* #param string $account
* #return Movement
*/
public function setAccount($account)
{
$this->Account = $account;
return $this;
}
/**
* Get Account
*
* #return string
*/
public function getAccount()
{
return $this->Account;
}
/**
* Set date
*
* #param \DateTime $date
* #return Movement
*/
public function setDate($date)
{
$this->date = $date;
return $this;
}
/**
* Get date
*
* #return \DateTime
*/
public function getDate()
{
return $this->date;
}
/**
* Set Type
*
* #param string $type
* #return Movement
*/
public function setType($type)
{
$this->Type = $type;
return $this;
}
/**
* Get Type
*
* #return string
*/
public function getType()
{
return $this->Type;
}
/**
* Set value
*
* #param float $value
* #return Movement
*/
public function setValue($value)
{
$this->value = $value;
return $this;
}
/**
* Get value
*
* #return float
*/
public function getValue()
{
return $this->value;
}
/**
* Set fromAccount
*
* #param string $fromAccount
* #return Movement
*/
public function setFromAccount($fromAccount)
{
$this->fromAccount = $fromAccount;
return $this;
}
/**
* Get fromAccount
*
* #return string
*/
public function getFromAccount()
{
return $this->fromAccount;
}
/**
* Set toAccount
*
* #param string $toAccount
* #return Movement
*/
public function setToAccount($toAccount)
{
$this->toAccount = $toAccount;
return $this;
}
/**
* Get toAccount
*
* #return string
*/
public function getToAccount()
{
return $this->toAccount;
}
/**
* Set ExpenseType
*
* #param string $expenseType
* #return Movement
*/
public function setExpenseType($expenseType)
{
$this->ExpenseType = $expenseType;
return $this;
}
/**
* Get ExpenseType
*
* #return string
*/
public function getExpenseType()
{
return $this->ExpenseType;
}
/**
* Set orderHolder
*
* #param string $orderHolder
* #return Movement
*/
public function setOrderHolder($orderHolder)
{
$this->orderHolder = $orderHolder;
return $this;
}
/**
* Get orderHolder
*
* #return string
*/
public function getOrderHolder()
{
return $this->orderHolder;
}
/**
* Set exchange rate for movement
*
* #param float $xrate
*/
public function setXrate($xrate)
{
$this->xrate = (double)$xrate;
return $this;
}
/**
* Return movement exchange rate
*
* #return float
*/
public function getXrate()
{
return $this->xrate;
}
}
Entity Account
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Account
*
* #ORM\Table(name="account")
*
* #ORM\Entity(repositoryClass="Far\MT\AccountBundle\Entity\AccountRepository")
*/
class Account
{
public function __construct()
{
$this->holders = new ArrayCollection();
$this->pocketAccounts = new ArrayCollection();
}
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="code", type="string", length=40)
*/
private $code;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* #var string
*
* #ORM\Column(name="currency", type="string", length=20)
*/
private $currency;
/**
* #var Far\MT\AccountBundle\Entity\Holder
*
* #ORM\ManyToMany(targetEntity="Holder", inversedBy="Accounts")
* #ORM\JoinTable(name="account_holder",
* joinColumns={#ORM\JoinColumn(name="account_id", referencedColumnName="id")},
* inverseJoinColumns={#ORM\JoinColumn(name="holder_id",
* referencedColumnName="id")}
* )
*
*/
private $holders;
/**
* #var Far\MT\AccountBundle\Entity\Account
*
* #ORM\OneToMany(targetEntity="Account", mappedBy="parentAccount")
*/
private $pocketAccounts;
/**
*
* #ORM\ManyToOne(targetEntity="Account", inversedBy="pocketAccounts", cascade={"persist"})
* #ORM\JoinColumn(name="parent_id", referencedColumnName="id")
*/
private $parentAccount;
/**
* Specifies the account type has string
*
* #var String
*
* #ORM\Column(name="accounttype", type="string", length=40)
*/
private $accountType;
/**
* Total value of available money this should not account money that is
* pending transaction
*
* #var double
*
* #ORM\Column(name="totalavailable", type="float")
*/
private $totalAvailable = 0;
/**
* Total value of accounted money this takes into account money that has
* pending transaction
*
* #var double
*
* #ORM\Column(name="totalaccounted", type="float")
*/
private $totalAccounted = 0;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set code
*
* #param string $code
* #return Account
*/
public function setCode($code)
{
$this->code = str_replace(" ", "", strtoupper(trim($code)));
return $this;
}
/**
* Get code
*
* #return string
*/
public function getCode()
{
return $this->code;
}
/**
* Set name
*
* #param string $name
* #return Account
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* Set currency
*
* #param string $currency
* #return Account
*/
public function setCurrency($currency)
{
$this->currency = $currency;
return $this;
}
/**
* Get currency
*
* #return string
*/
public function getCurrency()
{
return $this->currency;
}
/**
* Set holders
*
* #param null|Doctrine\Common\Collections\ArrayCollection $holders
* #return Account
*/
public function setHolders($holders)
{
if ($holders === null) {
$this->holders = new ArrayCollection();
} else {
$this->holders = $holders;
}
return $this;
}
/**
* Get holders
*
* #return string
*/
public function getHolders()
{
return $this->holders;
}
/**
*
* Get Pocket accounts
*
* #return \Doctrine\Common\Collections\ArrayCollection()
*/
public function getPocketAccounts()
{
return $this->pocketAccounts;
}
public function setPocketAccounts($PocketAccounts)
{
$this->pocketAccounts = $PocketAccounts;
return $this;
}
/**
* Get Parent Account
*
* #return \Far\MT\AccountBundle\Entity\Account
*
*/
public function getParentAccount()
{
return $this->parentAccount;
}
public function setParentAccount($ParentAccount)
{
$this->parentAccount = ($ParentAccount);
return $this;
}
/**
* does this account has a parent
*
* #return boolean
*/
public function hasParentAccount()
{
return ($this->parentAccount !== null);
}
public function setAccountType($accountType)
{
$this->accountType = $accountType;
return $this;
}
public function getAccountType()
{
return $this->accountType;
}
public function getTotalAccounted()
{
return $this->totalAccounted;
}
public function setTotalAccounted($total)
{
$this->totalAccounted = $total;
return $this;
}
public function getTotalAvailable()
{
return $this->totalAvailable;
}
public function setTotalAvailable($total)
{
$this->totalAvailable = $total;
return $this;
}
public function __toString()
{
return 'Account';
}
}
Please note that what is updated is the Movement entity witch contains the Account in fromAccount and toAccount.
Not knowing the answer he pointed out to me that I did not understand the data_class parameter.
'data_class' => 'Far\MT\AccountBundle\Entity\Account'
18:37 < ocramius> netcrash: no, sorry, can't help since I don't know
what data_class does (not a sf2 form user)
I was missing a Data Transformer, data_class (specifying the Entity was working not sure the reason why...), I placed a DataTransformer and it solved the issue.
See bellow.
use Far\MT\AccountBundle\Form\DataTransformer\AccountToIdTransformer;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class Accounts extends AbstractType
{
/**
*
* #var EntityManager
*/
private $em;
private $accountrepo = null;
private $choices = array();
public function buildForm(FormBuilderInterface $builder, array $options)
{
parent::buildForm($builder, $options);
$transformer = new AccountToIdTransformer($this->em);
$builder->addModelTransformer($transformer);
}
public function setAccountRepository($repo)
{
$this->accountrepo = $repo;
return $this;
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults([
'choices' => $this->getChoices(),
'attr' => [
'data-dojo-type' => 'dijit/form/FilteringSelect',
]
]);
}
public function getParent()
{
return 'choice';
}
public function getName()
{
return 'Accounts';
}
public function getChoices()
{
if ( count($this->choices) > 0 ) {
return $this->choices;
}
$this->choices[0] = "";
foreach ($this->accountrepo->findAll() as $account) {
$this->choices[$account->getId()] = $account->getName() . " (" .
$account->getCurrency().") ";
}
return $this->choices;
}
}
And the data transformer:
/**
* This is a transformer for the Account AbstractType
*
* #link http://symfony.com/doc/master/cookbook/form/data_transformers.html
*
* #author andref
*/
class AccountToIdTransformer implements DataTransformerInterface
{
/**
* #var ObjectManager
*/
private $om;
/**
*
* #param ObjectManager $om
*/
public function __construct($om)
{
$this->om = $om;
}
/**
* Transforms an object (issue) to a int (Id).
*
* #param Account|null $account
* #return string
*/
public function transform($account)
{
if (null === $account) {
return "";
}
return $account->getId();
}
/**
* Transforms a int (Id) to an object (Account).
*
* #param int $Id
*
* #return Account|null
*
* #throws TransformationFailedException if object (Account) is not found.
*/
public function reverseTransform($id)
{
if (!$id) {
return null;
}
$Account = $this->om
->getRepository('FarMTAccountBundle:Account')
->findOneBy(array('id' => $id))
;
if (null === $Account) {
throw new TransformationFailedException(sprintf(
'An Account with Id "%s" does not exist!',
$id
));
}
return $Account;
}
}

Categories