I need to get array of orders, with first and last OrderItem in it.
Table order_item:
id
order_id
status
1
1
0
2
1
1
3
1
0
4
1
1
5
1
0
Order entity
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
/**
* Order
*
* #ORM\Entity
* #ORM\Table(name="orders")
*/
class Order
{
/**
* #var int
* #ORM\Column(name="id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
* #Serializer\Groups(groups="order_list")
*/
private $id;
/**
* #var string
* #ORM\Column(name="title", type="string", nullable=false)
* #Serializer\Groups(groups={"order_list"})
*/
private $title;
/**
* #var Collection
* #ORM\OneToOne(targetEntity="OrderItem", mappedBy="orderFirst")
* #Serializer\Groups(groups={"order_list"})
*/
private $orderItemFirst;
/**
* #var Collection
* #ORM\OneToOne(targetEntity="OrderItem", mappedBy="orderLast")
* #Serializer\Groups(groups={"order_list"})
*/
private $orderItemLast;
/**
* #var Collection|OrderItem[]
* #ORM\OneToMany(targetEntity="OrderItem", mappedBy="order")
* #Serializer\Groups(groups={"order_list"})
*/
private $items;
public function __construct()
{
$this->items = new ArrayCollection();
}
// getters and setters ...
}
OrderItem entity
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
/**
* Order
*
* #ORM\Entity
* #ORM\Table(name="order_item")
*/
class OrderItem
{
/**
* #var int
* #ORM\Column(name="id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
* #Serializer\Groups(groups="order_list")
*/
private $id;
/**
* #var Order|null
* #ORM\OneToOne(targetEntity="Order", inversedBy="orderItemFirst")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="order_id", referencedColumnName="id")
* })
*/
private $orderFirst;
/**
* #var Order|null
* #ORM\OneToOne(targetEntity="Order", inversedBy="orderItemLast")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="order_id", referencedColumnName="id")
* })
*/
private $orderLast;
/**
* #var Order|null
* #ORM\ManyToOne(targetEntity="Order", inversedBy="items")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="order_id", referencedColumnName="id")
* })
*/
private $order;
/**
* #var bool
* #ORM\Column(type="boolean", nullable=false)
* #Serializer\Groups(groups="order_list")
*/
private $status;
// getters and setters...
}
Code in service
$repository = $em->getRepository(\App\Entity\Order::class);
$qb = $repository->createQueryBuilder('t');
$qb
->leftJoin('t.orderItemFirst', 'oi', \Doctrine\ORM\Query\Expr\Join::WITH, 'oi.status = :status')
->leftJoin('t.orderItemFirst', 'oi2', \Doctrine\ORM\Query\Expr\Join::WITH, 'oi2.status = :status AND oi2.id > oi.id')
->leftJoin('t.orderItemLast', 'oi3', \Doctrine\ORM\Query\Expr\Join::WITH, 'oi3.status = :status')
->leftJoin('t.orderItemLast', 'oi4', \Doctrine\ORM\Query\Expr\Join::WITH, 'oi4.status = :status AND oi4.id < oi3.id')
->setParameter('status', true)
->addSelect('oi')
->addSelect('oi3')
->where('oi2.id IS NULL')
->andWhere('oi4.id IS NULL')
->groupBy('t.id')
;
$query = $qb->getQuery();
$query->setHint(\Doctrine\ORM\Query::HINT_REFRESH, true);
/*
* This returns
* "orderItemFirst": {"id": 4}
* "orderItemLast": {"id": 4}
*/
$result = $query->getResult();
But getArrayResult() returns correct data:
"orderItemFirst": {
"id": 2,
"status": true
},
"orderItemLast": {
"id": 4,
"status": true
}
And even if I call getArrayResult() at first, getResult() starts to hydrate correctly. What a strange behavior? Can it be done without double executing query?
Related
I'm trying to use JMS serializer in my application (not Symfony) and would like to deserialize a JSON object to the Doctrine Entity.
The plain properties are getting properly deserialized, but I can't get the ArrayCollections to work.
This is an excerpt of my product JSON:
{
"id": 2,
"name": "Shirt blue",
"attributeValues": [
{
"id": 4,
"title": "S",
"attributeId": 2
},
{
"id": 7,
"title": "Eterna",
"attributeId": 3
}
]
}
This is my Product entity:
<?php
namespace Vendor\App\Common\Entities;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as JMS;
/**
* #ORM\Entity
* #ORM\HasLifecycleCallbacks
* #ORM\Table(name="product")
* #JMS\ExclusionPolicy("all")
*/
class Product extends AbstractEntity {
/**
* #var int $id
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
* #ORM\Column(name="id", type="integer", nullable=false)
* #JMS\Groups({"search"})
* #JMS\Expose
* #JMS\Type("integer")
*/
protected $id;
/**
* #var string $name
* #ORM\Column(name="name", type="string", nullable=false)
* #JMS\Expose
* #JMS\Groups({"search"})
* #JMS\Type("string")
*/
protected $name;
/**
* #var ArrayCollection $attributeValues
* #ORM\ManyToMany(targetEntity="Vendor\App\Common\Entities\Attribute\Value")
* #ORM\JoinTable(name="products_values",
* joinColumns={#ORM\JoinColumn(name="product_id", referencedColumnName="id")},
* inverseJoinColumns={#ORM\JoinColumn(name="value_id", referencedColumnName="id")}
* )
* #JMS\Expose
* #JMS\MaxDepth(2)
* #JMS\Groups({"search"})
* #JMS\Type("ArrayCollection<Vendor\App\Common\Entities\Attribute\Value>")
*/
protected $attributeValues;
public function __construct() {
$this->attributeValues = new ArrayCollection();
}
/**
* #return ArrayCollection
*/
public function getAttributeValues() {
return $this->attributeValues;
}
/**
* #param ArrayCollection $attributeValues
*/
public function setAttributeValues($attributeValues) {
$this->attributeValues = $attributeValues;
}
/**
* #param Value $attributeValue
*/
public function addAttributeValue($attributeValue) {
$this->attributeValues->add($attributeValue);
}
/**
* #param Value $attributeValue
*/
public function removeAttributeValue($attributeValue) {
$this->attributeValues->removeElement($attributeValue);
}
}
This is my Value entity that should be deserialized in the ArrayCollection:
<?php
namespace Vendor\App\Common\Entities\Attribute;
use Vendor\App\Common\Entities\AbstractEntity,
Doctrine\ORM\Mapping as ORM,
JMS\Serializer\Annotation as JMS;
/**
* #ORM\Entity
* #ORM\Table(name="attribute_value")
* #JMS\ExclusionPolicy("all")
*/
class Value extends AbstractEntity {
/**
* #var int $id
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
* #ORM\Column(name="id", type="integer", nullable=false)
* #JMS\Expose
* #JMS\Groups({"search"})
* #JMS\Type("integer")
*/
protected $id;
/**
* #var string $title
* #ORM\Column(name="title", type="string", nullable=false)
* #JMS\Expose
* #JMS\Groups({"search"})
* #JMS\Type("string")
*/
protected $title;
/**
* #var int $attributeId
* #ORM\Column(name="attribute_id", type="integer", nullable=false)
* #JMS\Expose
* #JMS\Groups({"search"})
* #JMS\Type("integer")
*/
protected $attributeId;
/**
* OWNING SIDE
* #var \Vendor\App\Common\Entities\Attribute $attribute
* #ORM\ManyToOne(targetEntity="Vendor\App\Common\Entities\Attribute", inversedBy="values")
* #ORM\JoinColumn(name="attribute_id", referencedColumnName="id")
* #JMS\Expose
* #JMS\Groups({"search"})
* #JMS\Type("Vendor\App\Common\Entities\Attribute")
*/
protected $attribute;
//Getters and setters ...
}
Just trying to simply deserialize the entity:
$serializer = SerializerBuilder::create()->build();
$entity = $serializer->deserialize($sourceJson, Product::class, 'json');
But the attributeValue ArrayCollection stays empty. What am I missing?
I found the solution. JMS has a default naming strategy which converts camelcase to underscore notation.
Default is that the naming strategy either looks for the annotation #SerializedName and if that is not set, it will convert CamelCase to underscore.
So the property just got ignored because it didn't match the expected name. Of course, it would be better if there was an error or a notification which gives a hint here on where to search for the problem (something like unknown property would have been nice).
$serializer = SerializerBuilder::create()->setPropertyNamingStrategy(new IdenticalPropertyNamingStrategy())->build();
Was the solution.
Does anyone know why the Doctrine query below creates a separate join for the StandardDedescribed entity?
As you can see below this query pulls the information from the master entity 'EquipmentUK' and two related tables: 'SchemaInfo' and 'StandardDescribed'. It works well for the SchemaInfo, but creates another query for StandardDescribed. The relations in the Entities seem to be coded extactly the same, so I don't understand why it behaves differently for StandardDescribed?
$qb->select('e')
->from('\Lookup\Entity\Fullhistory\EquipmentUK', 'e')
->leftJoin(
'\Lookup\Entity\Fullhistory\SchemaInfo',
'si',
Expr\Join::WITH,
'e.schema_id = si.schema_id AND si.parent_schema_id != si.schema_id'
)
->leftJoin(
'\Lookup\Entity\Intelligence\StandardDescribedUK',
'sd',
Expr\Join::WITH,
'e.schema_id = sd.schema_id'
)
->where($qb->expr()->eq('e.vehicle_id', '?1'))
->setParameter(1, $jatoid);
Here are the Entities:
EquipmentUK:
namespace Lookup\Entity\Fullhistory;
use Doctrine\ORM\Mapping as ORM;
/**
* EquipmentUK
*
* #ORM\Table(name="equipment",
* uniqueConstraints={
* #ORM\UniqueConstraint(name="search_idx", columns={"vehicle_id", "option_id", "record_id", "schema_id"})
* }
* )
* #ORM\Entity
*/
class EquipmentUK
{
/**
* #var integer
*
* #ORM\Id
* #ORM\Column(type="integer")
*/
private $vehicle_id;
/**
* #var integer
*
* #ORM\Id
* #ORM\Column(type="integer")
*/
private $schema_id;
/**
* #var integer
*
* #ORM\Id
* #ORM\Column(type="integer")
*/
private $option_id;
/**
* #var integer
*
* #ORM\Id
* #ORM\Column(type="integer")
*/
private $record_id;
/**
* #var string
*
* #ORM\Column(type="string")
*/
private $location;
/**
* #ORM\ManyToOne(targetEntity="Lookup\Entity\Fullhistory\SchemaInfo", cascade={"all"}, fetch="EAGER")
* #ORM\JoinColumn(name="schema_id", referencedColumnName="schema_id")
*/
private $schemaInfo;
/**
* #ORM\ManyToOne(targetEntity="Lookup\Entity\Intelligence\StandardDescribedUK", cascade={"all"}, fetch="EAGER")
* #ORM\JoinColumn(name="schema_id", referencedColumnName="schema_id")
*/
private $standardDescribed;
/**
* #var string
*
* #ORM\Column(type="string")
*/
private $data_value;
public function getVehicleId()
{
return $this->vehicle_id;
}
public function getSchemaId()
{
return $this->schema_id;
}
public function getOptionId()
{
return $this->option_id;
}
public function getRecordId()
{
return $this->record_id;
}
public function getLocation()
{
return $this->location;
}
public function getSchemaInfo()
{
return $this->schemaInfo;
}
public function getStandardDescribed()
{
return $this->standardDescribed;
}
public function getDataValue()
{
return $this->data_value;
}
}
SchemaInfo:
namespace Lookup\Entity\Fullhistory;
use Doctrine\ORM\Mapping as ORM;
/**
* SchemaInfo
*
* #ORM\Table(name="schema_info")
* #ORM\Entity
*/
class SchemaInfo
{
/**
* #var integer
*
* #ORM\Column(name="schema_id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $schema_id;
/**
* #var integer
*
* #ORM\Column(name="parent_schema_id", type="integer", nullable=true)
*/
private $parent_schema_id;
/**
* #var integer
*
* #ORM\Column(name="location_schema_id", type="integer", nullable=true)
*/
private $locationSchemaId;
/**
* #var integer
*
* #ORM\Column(name="scale_of_data", type="smallint", nullable=true)
*/
private $scaleOfData;
/**
* #var integer
*
* #ORM\Column(name="data_type", type="smallint", nullable=true)
*/
private $dataType;
public function getSchemaId()
{
return $this->schema_id;
}
public function getParentSchemaId()
{
return $this->parent_schema_id;
}
}
StandardDescribedUK
namespace Lookup\Entity\Intelligence;
use Doctrine\ORM\Mapping as ORM;
/**
* StandardDescribedUK
*
* #ORM\Table(name="jato_uk_intelligence.standard_described")
* #ORM\Entity
*/
class StandardDescribedUK
{
/**
* #var integer
*
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $schema_id;
/**
* #var string
*
* #ORM\Column(name="category", type="string", nullable=true)
*/
private $category;
public function getCategory()
{
return $this->category;
}
}
Your joins should use Doctrine's own relational schema: your EquipmentUK has declared its relation with SchemaInfo via the property $schemaInfo, and it has also declared its relation with StandardDescribedUK via $standardDescribed. So:
$qb->select('e')
->from('\Lookup\Entity\Fullhistory\EquipmentUK', 'e')
->leftJoin(
'e.schemaInfo',
'si'
//we don't need that third param as the relation is already known
)
->leftJoin(
'e.standardDescribed',
'sd'
//same here, no need for explicit relation
)
->where($qb->expr()->eq('e.vehicle_id', ':vehicle'))
//this here is a restriction, should be in WHERE instead of ON
->andWhere($qb->expr()->neq('si.parent_schema_id', 'si.schema_id'))
->setParameter('vehicle', $jatoid);
Hope this helps!
I have two entities:
namespace Api\Payment\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* PaySystemField
*
* #ORM\Table(name="paysystem_field")
* #ORM\Entity
*/
class PaySystemField
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=50, nullable=false)
*/
private $name;
...
}
and
namespace Api\Payment\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* PaySystemFieldValue
*
* #ORM\Table(name="paysystem_field_value")
* #ORM\Entity
*/
class PaySystemFieldValue
{
...
/**
* #var \Api\Payment\Entity\PaySystemField
*
* #ORM\ManyToOne(targetEntity="\Api\Payment\Entity\PaySystemField", fetch="EAGER")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="paySystemFieldId", referencedColumnName="id")
* })
*/
private $paySystemField;
...
}
My DQL request:
$fieldsValues = $this->objectManager
->createQuery('
SELECT psfv,psf FROM Api\Payment\Entity\PaySystemFieldValue psfv
JOIN Api\Payment\Entity\PaySystemField psf WITH (psfv.paySystemField=psf.id)
WHERE psfv.payment=:payment
')
->setParameter('payment', $this->payment)
->setFetchMode('Api\Payment\Entity\PaySystemFieldValue', 'paySystemField', 'EAGER')
->getResult();
This query returns PaySystemFieldValue with paySystemField relation already initialised, but $fieldsValues contain both PaySystemFieldValue entities and PaySystemField. How can i do the way $fieldsValues will contain only PaySystemFieldValue entities with paySystemField relation initialised?
try with this query:
$fieldsValues = $this->objectManager->createQuery('SELECT psfv FROM Api\Payment\Entity\PaySystemFieldValue psfv WHERE psfv.payment=:payment')->setParameter('payment', $this->payment)->getResult();
or
$this->getServiceLocator()->get('doctrine.entitymanager.orm_default')->getRepository("Api\Payment\Entity\PaySystemFieldValue")->findBy(array('payment' => $this->payment));
how to get mapping table id from mappipng table?
i have user and group table mapped together
and i want to get group id at login time but i am not getting it.
i have three table
user, group, user_groupname
->first table
user
id,name
->second table
group
id,name
->third table
groupname
user_id,group_id
first entity is as follows
/Entity/groupname.php
class groupname
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255, nullable=false)
*/
private $name;
/**
* #var \Doctrine\Common\Collections\Collection
*
* #ORM\ManyToMany(targetEntity="role", inversedBy="groupname")
* #ORM\JoinTable(name="groupname_role",
* joinColumns={
* #ORM\JoinColumn(name="groupname_id", referencedColumnName="id")
* },
* inverseJoinColumns={
* #ORM\JoinColumn(name="role_id", referencedColumnName="id")
* }
* )
*/
private $role;
/**
* #ORM\ManyToMany(targetEntity="\Dashboard\SecurityBundle\Entity\User", mappedBy="groupname")
*/
private $users;
}
second entity is as follows
/Entity/User.php
<?php
namespace Dashboard\SecurityBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Dashboard\SecurityBundle\Entity\User
*
* #ORM\Table(name="users")
* #ORM\Entity(repositoryClass="Dashboard\SecurityBundle\Repository\UserRepository")
* #ORM\HasLifecycleCallbacks()
*/
class User implements UserInterface, \Serializable, AdvancedUserInterface
{
/**
* #ORM\Column(type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* #ORM\Column(type="string", length=25, unique=true)
*/
protected $username;
*/
/**
* #ORM\ManyToMany(targetEntity="\Dashboard\AdminManageUserBundle\Entity\groupname", inversedBy="users")
*
*/
public $groupname;
/**
* #var Dashboard\SecurityBundle\Entity\UserPhoto UserPhoto
*
*/
private $userPhoto;
public function __construct()
{
$this->groupname = new ArrayCollection();
}
/**
* Add groupname
*
* #param \Dashboard\AdminManageUserBundle\Entity\groupname $groupname
* #return User
*/
public function addGroupname(\Dashboard\AdminManageUserBundle\Entity\groupname $groupname)
{
$this->groupname[] = $groupname;
return $this;
}
/**
* Remove groupname
*
* #param \Dashboard\AdminManageUserBundle\Entity\groupname $groupname
*/
public function removeGroupname(\Dashboard\AdminManageUserBundle\Entity\groupname $groupname)
{
$this->groupname->removeElement($groupname);
}
/**
* Get groupname
*
* #return \Doctrine\Common\Collections\ArrayCollection
*/
public function getGroupname()
{
return $this->groupname;
}
}
and i have following code right in Controller file
$userEntity = $this->getDoctrine()->getRepository('DashboardSecurityBundle:User')->findOneBy(array('username' =>$usernames));
and i have print_R($userEntity) pc got hanged
$userEntiry is a object of UserEntity
So, your pc got hanged.
please try this.
print_r($userEntity->getUsername());
I've been playing around with Zend and Doctrine incorporated into it for the past week or so. I've gotten the hang of basic inserts and selects, and can also use DQL to select from joined tables. The problem I'm having is persisting associated entities. Error I'm getting is this: (path)htdocs\vendor\doctrine\common\lib\Doctrine\Common\Persistence\Mapping\MappingException.php:96 with the message 'Class "" does not exist'.
My code is below...
Here is the main entity (the one on the "many" side)
namespace Project\Entity;
use Doctrine\ORM\Mapping as ORM;
use Zend\InputFilter\Factory as InputFactory;
/**
* ClientUser
*
* #ORM\Table()
* #ORM\Entity
*/
class ClientUser extends SystemUser
{
/**
* #var integer
*
* #ORM\OneToOne(targetEntity="SystemUser", cascade={"persist", "remove"})
* #ORM\JoinColumn(name="id", referencedColumnName="id")
*/
private $id;
/**
* #var integer
*
* #ORM\ManyToOne(targetEntity="Client", cascade={"persist", "remove"})
* #ORM\JoinColumn(name="client", referencedColumnName="id")
*/
private $client;
protected $_inputFilter;
//Other stuff here...
}
Here is the "Client" associated entity...
namespace Project\Entity;
use Doctrine\ORM\Mapping as ORM;
use Zend\InputFilter\InputFilter;
use Zend\InputFilter\Factory as InputFactory;
use Zend\InputFilter\InputFilterAwareInterface;
use Zend\InputFilter\InputFilterInterface;
/**
* Client
*
* #ORM\Table()
* #ORM\Entity
*/
class Client implements InputFilterAwareInterface
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="client_name", type="string", length=255)
*/
private $clientName;
/**
* #var integer
*
* #ORM\Column(name="loggable_hours", type="integer")
*/
private $loggableHours;
/**
* #var float
*
* #ORM\Column(name="normal_rate", type="decimal", scale=2)
*/
private $normalRate;
/**
* #var float
*
* #ORM\Column(name="critical_rate", type="decimal", scale=2)
*/
private $criticalRate;
/**
* #var string
*
* #ORM\Column(name="start_date", type="string")
*/
private $startDate;
/**
* #var boolean
*
* #ORM\Column(name="enabled", type="boolean")
*/
private $enabled;
/**
* #var integer
*
* #ORM\Column(name="critical_hours", type="integer")
*/
private $criticalHours;
/**
*
* #var type
*/
protected $_inputFilter;
//Other stuff (getters,setters, etc)
}
The ClientUser has a one-to-one relationship with the following:
namespace Project\Entity;
use Doctrine\ORM\Mapping as ORM;
use Zend\InputFilter\InputFilter;
use Zend\InputFilter\Factory as InputFactory;
use Zend\InputFilter\InputFilterAwareInterface;
use Zend\InputFilter\InputFilterInterface;
/**
* SystemUser
*
* #ORM\Table()
* #ORM\Entity
* #ORM\InheritanceType("JOINED")
* #ORM\DiscriminatorColumn(name="user_type", type="integer")
* #ORM\DiscriminatorMap({1 = "DeveloperUser", 2 = "ClientUser"})
*
*/
class SystemUser implements InputFilterAwareInterface {
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="username", type="string", length=100, unique=true)
*/
private $username;
/**
* #var string
*
* #ORM\Column(name="password", type="string", length=255)
*/
private $password;
/**
* #var string
*
* #ORM\Column(name="user_first_name", type="string", length=255)
*/
private $userFirstName;
/**
* #var string
*
* #ORM\Column(name="user_surname", type="string", length=255)
*/
private $userSurname;
/**
* #ORM\Column(type="string", length=32)
*/
private $salt;
/**
* #var \DateTime
*
* #ORM\Column(name="last_login", type="datetime")
*/
private $lastLogin = '0000-00-00 00:00:00';
/**
* #var bool
*
* #ORM\Column(name="enabled", type="boolean", options={"default" = 1})
*/
private $enabled = 1;
/**
* For the input filter...
*
* #var InputFilter
*/
protected $_inputFilter;
//The rest...
}
I have absolutely no idea what could be wrong here... Just for completeness, here is the controller "add" action...
public function addAction() {
//To add clients
$form = new ClientUserForm($this->getServiceLocator()
->get('Doctrine\ORM\EntityManager'));
$form->get('submit')->setValue('Add');
$request = $this->getRequest();
if ($request->isPost()) {
$clientUser = new ClientUser();
$form->setInputFilter($clientUser->getInputFilter());
$form->setData($request->getPost());
if ($form->isValid()) {
$clientUser->populate($form->getData());
/**
*This bottom line is where I get the exception!
*/
$this->getEntityManager()->persist($clientUser);
$this->getEntityManager()->flush();
//Redirect
return $this->redirect()->toRoute('client_user');
}
}
return array ('form' => $form);
}
Any help would be awesome! If I just knew which class "" is supposed to be, I'd probably be in a better place than I am now!
Thanks ladies and gents, you guys rock!
EDIT-
Forgot to add these 2 PHP warnings...
Warning: spl_object_hash() expects parameter 1 to be object, integer given in (path)\htdocs\vendor\doctrine\orm\lib\Doctrine\ORM\UnitOfWork.php on line 1588
Warning: get_class() expects parameter 1 to be object, integer given in (path)\vendor\doctrine\orm\lib\Doctrine\ORM\UnitOfWork.php on line 1596
Im not sure of what could be happening, but i find something that i dont understand. When you states the inheritance, you use:
* #ORM\DiscriminatorColumn(name="user_type", type="integer")
* #ORM\DiscriminatorMap({1 = "DeveloperUser", 2 = "ClientUser"})
but
there isnt a class called DeveloperUser
and also
are you sure that in the database, all user_type are just 1 or 2? (no null, not 0, etc)