Symfony2 + Doctrine One-to-Many relationship - symfony

I'm trying to apply Doctrine to an existing database that has a OneToMany relationship between two tables: Commerce and Area.
I generated the yml schema from the database resulting in the following:
Area:
type: entity
table: area
fields:
id:
id: true
type: integer
unsigned: false
nullable: false
generator:
strategy: IDENTITY
name:
type: string
length: 255
fixed: false
nullable: true
lifecycleCallbacks: { }
Commerce:
type: entity
table: commerce
fields:
id:
id: true
type: integer
unsigned: false
nullable: false
generator:
strategy: IDENTITY
name:
type: string
length: 255
fixed: false
nullable: true
manyToOne:
area:
targetEntity: Area
cascade: { }
mappedBy: null
inversedBy: null
joinColumns:
area_id:
referencedColumnName: id
orphanRemoval: false
lifecycleCallbacks: { }
From that schema I generated the Entities:
use Doctrine\ORM\Mapping as ORM;
/**
* Model\EntitiesBundle\Entity\Area
*
* #ORM\Table(name="area")
* #ORM\Entity
*/
class Area
{
/**
* #var integer $id
*
* #ORM\Column(name="id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var string $name
*
* #ORM\Column(name="name", type="string", length=255, nullable=true)
*/
private $name;
/**
* #return string
*/
public function getName()
{
return $this->name;
}
}
use Doctrine\ORM\Mapping as ORM;
/**
* Model\EntitiesBundle\Entity\Commerce
*
* #ORM\Table(name="commerce")
* #ORM\Entity
*/
class Commerce
{
/**
* #var integer $id
*
* #ORM\Column(name="id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var string $name
*
* #ORM\Column(name="name", type="string", length=255, nullable=true)
*/
private $name;
/**
* #var Area
*
* #ORM\ManyToOne(targetEntity="Area")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="area_id", referencedColumnName="id")
* })
*/
private $area;
/**
* #return \Model\EntitiesBundle\Entity\Area
*/
public function getArea()
{
return $this->area;
}
/**
* #return string
*/
public function getName()
{
return $this->name;
}
}
My problem comes when I try:
$commerce = $em->getRepository('ModelEntitiesBundle:Commerces')
->find($id);
echo $commerce->getArea()->getName();
The Area entity has empty attributes.
Any ideas? Thank you!

I solved the problem. It was somewhere else, I have two Entity Managers and the one I needed was not the default.

Related

FOSRestBundle not use JMSSerializerBundle

I have configured Symfony 3 to auto serialize my action. It works, but the relations aren't serialized:
0
id 1
name "Liste de course"
creation_date "2017-07-07T00:00:00+00:00"
last_update_date "2017-07-07T20:57:06+00:00"
user_entity
_todo_entity_entities
_parent_entity
1
id 2
name "domotique"
creation_date "2017-07-07T00:00:00+00:00"
last_update_date "2017-07-07T21:22:52+00:00"
user_entity
_todo_entity_entities
_parent_entity
If I explicitly use JMSSerializerBundle, it works (user_entity is an object):
0
id 1
name "Liste de course"
creation_date "2017-07-07T00:00:00+00:00"
last_update_date "2017-07-07T20:57:06+00:00"
user_entity Object
_todo_entity_entities
1
id 2
name "domotique"
creation_date "2017-07-07T00:00:00+00:00"
last_update_date "2017-07-07T21:22:52+00:00"
user_entity Object
_todo_entity_entities
I think FOSRestBundle uses the default seralizer, not JMSSerializerBundle:
/**
* #Rest\Get("/projects")
* #View(
* serializerGroups = {"all"}
* )
*/
public function getProjectsAction()
{
$projectEntity = $this->getDoctrine()->getRepository('todoListAdminBundle:Project');
$projects = $projectEntity->findAll();
/*
$data = $this->get('jms_serializer')->serialize($projects, 'json');
// this is work !
$response = new Response($data);
$response->headers->set('Content-Type', 'application/json');
return $response;
*/
return $projects;
}
The entity I serialize :
/**
* Project
*
* #ORM\Table(name="project")
* #ORM\Entity(repositoryClass="todoListAdminBundle\Repository\ProjectRepository")
*/
class Project
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
* #Serializer\Groups({"all"})
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255)
* #Assert\Length(max=50)
* #Assert\Type(type="string")
* #Serializer\Groups({"all"})
*/
private $name;
/**
* #var \DateTime
*
* #ORM\Column(name="creation_date", type="date")
* #Assert\DateTime()
* #Serializer\Groups({"all"})
*/
private $creationDate;
/**
* #var \DateTime
*
* #ORM\Column(name="last_update_date", type="datetime")
* #Assert\DateTime()
* #Serializer\Groups({"all"})
*/
private $lastUpdateDate;
/**
*
* #ORM\ManyToOne(targetEntity="PW\UserBundle\Entity\User", inversedBy="projectEntities" , cascade={"persist"}, inversedBy="projectEntities")
* #Assert\Type(type="integer")
* #Serializer\Groups({"all"})
*/
private $userEntity;
/**
* #ORM\OneToMany(targetEntity="todoListAdminBundle\Entity\TodoEntity", mappedBy="projectEntity", fetch="EAGER")
* #Serializer\Groups({"all"})
*/
private $TodoEntityEntities;
/**
* #var int
*
* #ORM\JoinColumn(nullable=true, referencedColumnName="id")
* #ORM\OneToOne(targetEntity="todoListAdminBundle\Entity\Project")
* #Assert\Type(type="integer")
* #Serializer\Groups({"all"})
*/
private $ParentEntity;
My configuration :
fos_rest:
param_fetcher_listener: true
body_listener: true
zone:
- { path: ^/api/* }
body_converter:
enabled: true
view:
formats: { json: true, xml: false, rss: false }
view_response_listener: true
serializer:
serialize_null: true
format_listener:
enabled: true
rules:
- { path: '^/api', priorities: ['json'], fallback_format: 'json' }
routing_loader:
default_format: json
sensio_framework_extra:
view: { annotations: true }
How can I use JMSSerializerBundle automatically ?
First of all, you need to configure JMSSerializer in your config.yml like:
jms_serializer:
metadata:
cache: file
debug: "%kernel.debug%"
file_cache:
dir: "%kernel.cache_dir%/serializer"
auto_detection: true
Then, create directory with serializer for the given entity YourBundleName/Resources/config/serializer/Entity.Project.yml with this code:
YourBundleName\Entity\Project:
exclusion_policy: ALL
properties:
id:
expose: true
name:
expose: true
"exclusion_policy: ALL" - exclude all the fields from the serialized result. And then you add needed fields with "expose: true". Just do not add "ParentEntity" there and you will not see it in the serialized data (also, I do not think, that mix of camel and pascal case is a good practice, but it's the question of taste).

symfony2 persist manyToOne

i Have a single page application and i use symfony as a Rest API.
In my object "ResidenceIntervenant, i have a ManyToOne relation :
manyToOne:
intervenant:
targetEntity: Intervenant
cascade: { }
fetch: LAZY
mappedBy: null
inversedBy: null
joinColumns:
intervenant_id:
referencedColumnName: id
orphanRemoval: false
When i do this :
$myData = json_decode($request->getContent(), true);
$intervenant = $this->em->getRepository('AppBundle:Intervenant')->find($intervenantId);
$relation = new ResidenceIntervenant();
$myData['intervenant'] = $intervenant->getId();
$form_relation = $this->formFactory->create(ResidenceIntervenantType::class, $relation, ['method' => "POST"]);
$form_relation->submit($myData, TRUE);
if ( ! $form_relation->isValid()) {
$this->em->persist($relation);
$this->em->flush();
}
it works and i have the id in my table
When i do :
$myData = json_decode($request->getContent(), true);
$intervenant = $this->em->getRepository('AppBundle:Intervenant')->find($intervenantId);
$relation = new ResidenceIntervenant();
$relation->setIntervenant($intervenant);
$form_relation = $this->formFactory->create(ResidenceIntervenantType::class, $relation, ['method' => "POST"]);
$form_relation->submit($myData, TRUE);
if ( ! $form_relation->isValid()) {
$this->em->persist($relation);
$this->em->flush();
}
it doesn't persists the id
Is this normal ?
my FormType biuldForm method :
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('contratNum')
->add('appareilNum')
->add('intervenantOrigine')
->add('intervenant')
->add('residence');
}
Thanks for your help
EDIT : add informations to show my entities
I tried to add these linee but it neither works:
$intervenant->addResidenceIntervenant($relation);
$this->em->persist($intervenant);
$this->em->flush();
ResidenceIntervenant Entity :
<?php
namespace AppBundle\Entity;
/**
* ResidenceIntervenant
*/
class ResidenceIntervenant
{
/**
* #var integer
*/
private $id;
/**
* #var string
*/
private $contratNum;
/**
* #var string
*/
private $appareilNum;
/**
* #var boolean
*/
private $intervenantOrigine;
/**
* #var \AppBundle\Entity\Intervenant
*/
private $intervenant;
/**
* #var \AppBundle\Entity\Residence
*/
private $residence;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set contratNum
*
* #param string $contratNum
*
* #return ResidenceIntervenant
*/
public function setContratNum($contratNum)
{
$this->contratNum = $contratNum;
return $this;
}
/**
* Get contratNum
*
* #return string
*/
public function getContratNum()
{
return $this->contratNum;
}
/**
* Set appareilNum
*
* #param string $appareilNum
*
* #return ResidenceIntervenant
*/
public function setAppareilNum($appareilNum)
{
$this->appareilNum = $appareilNum;
return $this;
}
/**
* Get appareilNum
*
* #return string
*/
public function getAppareilNum()
{
return $this->appareilNum;
}
/**
* Set intervenantOrigine
*
* #param boolean $intervenantOrigine
*
* #return ResidenceIntervenant
*/
public function setIntervenantOrigine($intervenantOrigine)
{
$this->intervenantOrigine = $intervenantOrigine;
return $this;
}
/**
* Get intervenantOrigine
*
* #return boolean
*/
public function getIntervenantOrigine()
{
return $this->intervenantOrigine;
}
/**
* Set intervenant
*
* #param \AppBundle\Entity\Intervenant $intervenant
*
* #return ResidenceIntervenant
*/
public function setIntervenant(\AppBundle\Entity\Intervenant $intervenant = null)
{
$this->intervenant = $intervenant;
return $this;
}
/**
* Get intervenant
*
* #return \AppBundle\Entity\Intervenant
*/
public function getIntervenant()
{
return $this->intervenant;
}
/**
* Set residence
*
* #param \AppBundle\Entity\Residence $residence
*
* #return ResidenceIntervenant
*/
public function setResidence(\AppBundle\Entity\Residence $residence = null)
{
$this->residence = $residence;
return $this;
}
/**
* Get residence
*
* #return \AppBundle\Entity\Residence
*/
public function getResidence()
{
return $this->residence;
}
}
ResidenceIntervenant.orm.yml
AppBundle\Entity\ResidenceIntervenant:
type: entity
table: residence_intervenant
indexes:
fk_residence_intervenant_interv_id_idx:
columns:
- intervenant_id
fk_residence_intervenant_res_id_idx:
columns:
- residence_id
id:
id:
type: integer
nullable: false
options:
unsigned: false
id: true
generator:
strategy: IDENTITY
fields:
contratNum:
type: string
nullable: true
length: 100
options:
fixed: false
column: contrat_num
appareilNum:
type: string
nullable: true
length: 100
options:
fixed: false
column: appareil_num
intervenantOrigine:
type: boolean
nullable: false
options:
default: false
column: intervenant_origine
manyToOne:
intervenant:
targetEntity: Intervenant
cascade: ["persist"]
fetch: LAZY
mappedBy: null
inversedBy: null
joinColumns:
intervenant_id:
referencedColumnName: id
orphanRemoval: false
residence:
targetEntity: Residence
cascade: { }
fetch: LAZY
mappedBy: null
inversedBy: null
joinColumns:
residence_id:
referencedColumnName: id
orphanRemoval: false
lifecycleCallbacks: { }
Intervenant Entity :
<?php
namespace AppBundle\Entity;
/**
* Intervenant
*/
class Intervenant
{
/**
* #var integer
*/
private $id;
/**
* #var string
*/
private $libelleContact;
/**
* #var string
*/
private $url;
/**
* #var \AppBundle\Entity\Metier
*/
private $metier;
/**
* #var \AppBundle\Entity\Tiers
*/
private $tiers;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set libelleContact
*
* #param string $libelleContact
*
* #return Intervenant
*/
public function setLibelleContact($libelleContact)
{
$this->libelleContact = $libelleContact;
return $this;
}
/**
* Get libelleContact
*
* #return string
*/
public function getLibelleContact()
{
return $this->libelleContact;
}
/**
* Set url
*
* #param string $url
*
* #return Intervenant
*/
public function setUrl($url)
{
$this->url = $url;
return $this;
}
/**
* Get url
*
* #return string
*/
public function getUrl()
{
return $this->url;
}
/**
* Set metier
*
* #param \AppBundle\Entity\Metier $metier
*
* #return Intervenant
*/
public function setMetier(\AppBundle\Entity\Metier $metier = null)
{
$this->metier = $metier;
return $this;
}
/**
* Get metier
*
* #return \AppBundle\Entity\Metier
*/
public function getMetier()
{
return $this->metier;
}
/**
* Set tiers
*
* #param \AppBundle\Entity\Tiers $tiers
*
* #return Intervenant
*/
public function setTiers(\AppBundle\Entity\Tiers $tiers = null)
{
$this->tiers = $tiers;
return $this;
}
/**
* Get tiers
*
* #return \AppBundle\Entity\Tiers
*/
public function getTiers()
{
return $this->tiers;
}
/**
* #var \Doctrine\Common\Collections\Collection
*/
private $residenceIntervenant;
/**
* Constructor
*/
public function __construct()
{
$this->residenceIntervenant = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Add residenceIntervenant
*
* #param \AppBundle\Entity\ResidenceIntervenant $residenceIntervenant
*
* #return Intervenant
*/
public function addResidenceIntervenant(\AppBundle\Entity\ResidenceIntervenant $residenceIntervenant)
{
$this->residenceIntervenant[] = $residenceIntervenant;
return $this;
}
/**
* Remove residenceIntervenant
*
* #param \AppBundle\Entity\ResidenceIntervenant $residenceIntervenant
*/
public function removeResidenceIntervenant(\AppBundle\Entity\ResidenceIntervenant $residenceIntervenant)
{
$this->residenceIntervenant->removeElement($residenceIntervenant);
}
/**
* Get residenceIntervenant
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getResidenceIntervenant()
{
return $this->residenceIntervenant;
}
}
Intervenant.orm.yml :
AppBundle\Entity\Intervenant:
type: entity
table: intervenant
indexes:
fk_intervenant_metier_id_idx:
columns:
- metier_id
fk_intervenant_tiers_id_idx:
columns:
- tiers_id
id:
id:
type: integer
nullable: false
options:
unsigned: false
id: true
generator:
strategy: IDENTITY
fields:
libelleContact:
type: string
nullable: false
length: 255
options:
fixed: false
column: libelle_contact
url:
type: string
nullable: true
length: 255
options:
fixed: false
oneToMany:
residenceIntervenant:
targetEntity: ResidenceIntervenant
mappedBy: intervenant
cascade: [remove]
oneToOne:
tiers:
targetEntity: Tiers
joinColumn:
name: tiers_id
referencedColumnName: id
cascade: [remove, persist]
manyToOne:
metier:
targetEntity: Metier
cascade: ["persist"]
fetch: LAZY
mappedBy: null
inversedBy: null
joinColumns:
metier_id:
referencedColumnName: id
orphanRemoval: false
lifecycleCallbacks: { }
EDIT : Problem solved
i updated addResidenceIntervenant like this :
public function addResidenceIntervenant(\AppBundle\Entity\ResidenceIntervenant $residenceIntervenant)
{
$this->residenceIntervenant[] = $residenceIntervenant;
$residenceIntervenant->setIntervenant($this);
return $this;
}
i added these lines after persisting my relation :
$intervenant->addResidenceIntervenant($relation);
$this->em->persist($intervenant);
Your second example has this line:
$relation->setIntervenant($intervenant);
Does the method setIntervenant() set the relation?
I think you should do something like this:
public function setIntervenant(Intervenant $intervenant)
{
$this->intervenant = $intervenant;
$intervenant->setResidence($this);
}
Anyway, the relations in Doctrine can be unidirectional or bidirectional.
Your Many-To-One relation seems to be unidirectional. You should set a One-To-Many relation on your Intervenant entity.
Read more about this in the Doctrine documentation:
Many-to-One, Unidirectional (This is what you did)
One-to-Many, bidirectional (This is what you should do)
One-To-Many, Unidirectional with Join Table (Just for completeness)
So, you should trait your Intervenant as the Doctrine treats the Feature while your ResidenceIntervenant has to be treated as the Product in the Doctrine documentation.

Many to One Relation in Symfony 2

I have a problem related to Doctrine2:
1- I have two tables joining on a many-to-one relation:
Table 1 - Activity
The Schema:
Backend\adminBundle\Entity\Activity:
type: entity
table: activity
indexes:
result_id:
columns:
- result_id
id:
id:
type: integer
nullable: false
unsigned: false
comment: ''
id: true
generator:
strategy: IDENTITY
fields:
......
manyToOne:
result:
targetEntity: Actionresult
cascade: { }
mappedBy: null
inversedBy: null
joinColumns:
result_id:
referencedColumnName: id
orphanRemoval: false
The Entity
<?php
namespace Backend\adminBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
class Activity {
/**
* #var \Backend\adminBundle\Entity\Actionresult
*
* #ORM\ManyToOne(targetEntity="Backend\adminBundle\Entity\Actionresult")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="result_id", referencedColumnName="id")
* })
*/
private $result;
/**
* #var \Backend\adminBundle\Entity\SfGuardUser
*
* #ORM\ManyToOne(targetEntity="Backend\adminBundle\Entity\SfGuardUser")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="user_id", referencedColumnName="id")
* })
*/
/* There are other Properties */
/**
* Set result
*
* #param \Backend\adminBundle\Entity\Actionresult $result
* #return Activity
*/
public function setResult(\Backend\adminBundle\Entity\Actionresult $result = null)
{
$this->result = $result;
return $this;
}
/**
* Get result
*
* #return \Backend\adminBundle\Entity\Actionresult
*/
public function getResult()
{
return $this->result;
}
}
Table 2 - Actionresult Related to Activity Table by Id:
The schema:
Backend\adminBundle\Entity\Actionresult:
type: entity
table: actionresult
id:
id:
type: integer
nullable: false
unsigned: false
comment: ''
id: true
generator:
strategy: IDENTITY
fields:
name:
type: string
nullable: false
length: 255
fixed: false
comment: ''
lifecycleCallbacks: { }
The Entity:
<?php
namespace Backend\adminBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Actionresult
*
* #ORM\Table(name="actionresult")
* #ORM\Entity
*/
class Actionresult
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255, nullable=false)
*/
private $name;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* #param string $name
* #return Actionresult
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* #return string
*/
public function getName()
{
return $this->name;
}
}
The Question:
With doctrine i can refer from table Activity to Actionresult with the name result.
How can i refer with doctrine from table Actionresult to Activity??
Thank you in advance.
To be thorough, you should try and stick to one type of entity mapping in Symfony whenever possible. The #ORM* annotations are redundant if you use YAML config, and vice-versa. I'll provide the answer using YAML, and I believe you'll be able to convert to annotations if need be.
# Activity.yml
Activity:
type: entity
...
manyToOne:
result:
targetEntity: ActionResult
inversedBy: activities
# ActionResult.yml
Result:
type: entity
oneToMany:
activities:
targetEntity: Activity
mappedBy: result
# ActionResult.php
class Result {
protected $activities;
public function __construct()
{
$this->activities = new Doctrine\Common\Collections\ArrayCollection();
}
public function getActivities()
{
return $this->activities;
}
public function addActivity(Activity $activity)
{
$activity->setResult($this);
$this->activities->add($activity);
}
public function removeActivity(Activity $activity)
{
$activity->setResult(null);
$this->activities->removeElement($activity);
}
}
# Activity.php
class Activity {
protected $result;
public function getResult()
{
return $this->result;
}
public function setResult(ActionResult $result = null)
{
$this->result = $result;
}
}
Reference:
Bidirectional one to many: http://doctrine-orm.readthedocs.org/en/latest/reference/association-mapping.html#one-to-many-bidirectional

payum symfony 2 bundle - basic configuration - storage

I need to configure the payum bundle in order to let clients process paypal payments.
I just followed the getting started official recomendations, but need to configure something more, I guess (maybe I am missing to configure the storage for PaymentDetails somewhere).
my config files are as follows:
**app/config.yml**
doctrine:
orm:
auto_generate_proxy_classes: true
entity_managers:
default:
mappings:
WebsiteDeviceBundle: ~
WebsiteOnePageBundle: ~
payum:
is_bundle: false
type: xml
dir: %kernel.root_dir%/../vendor/payum/payum/src/Payum/Core/Bridge/Doctrine/Resources/mapping
prefix: Payum\Core\Model
payum:
security:
token_storage:
Website\Bundle\DeviceBundle\Entity\PaymentToken: { doctrine: orm }
storages:
Website\Bundle\DeviceBundle\Entity\PaymentDetails: { doctrine: orm }
contexts:
express_euro:
paypal_express_checkout_nvp:
username: ''
password: ''
signature: ''
sandbox: true
this is my controller action to start the payment process
public function prepareAction(){
$paymentName = 'express_euro';
$storage = $this->get('payum')->getStorage('Website\DeviceBundle\Entity\PaymentDetails');
$order = $storage->createModel();
$order->setNumber(uniqid());
$order->setCurrencyCode('EUR');
$order->setTotalAmount($this->view['user']->money);
$order->setDescrizione('annual account subscription');
$order->setUser($this->view['user']->getId());
$order->setCreatedAt(new \DateTime());
$order->setClientEmail($this->view['user']->getEmail());
$storage->updateModel($order);
$captureToken = $this->get('payum.security.token_storage')->createCaptureToken(
$paymentName,
$order,
'done' // the route to redirect after capture;
);
return $this->redirect($captureToken->getTargetUrl());
}
and this is PaymentDetails class
<?php
namespace Website\Bundle\DeviceBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Payum\Core\Model\ArrayObject;
/**
* PaymentDetails
*
* #ORM\Table(name="PaymentDetails", indexes={#ORM\Index(name="user", columns={"user"})})
* #ORM\Entity(repositoryClass="Website\Bundle\DeviceBundle\Entity\PaymentsDetailsRepository")
*/
class PaymentDetails extends ArrayObject
{
/**
* #var string
*
* #ORM\Column(name="currency_code", type="string", length=255, nullable=false)
*/
private $currencyCode;
/**
* #var string
*
* #ORM\Column(name="description", type="text", nullable=true)
*/
private $description;
/**
* #var \DateTime
*
* #ORM\Column(name="created_at", type="datetime", nullable=true)
*/
private $createdAt;
/**
* #var integer
*
* #ORM\Column(name="number", type="integer", nullable=false)
*/
private $number;
/**
* #var integer
*
* #ORM\Column(name="total_amount", type="integer", nullable=false)
*/
private $totalAmount;
/**
* #var string
*
* #ORM\Column(name="client_email", type="text", nullable=false)
*/
private $clientEmail;
/**
* #var integer
*
* #ORM\Column(name="id", type="bigint")
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var \Website\Bundle\DeviceBundle\Entity\Users
*
* #ORM\ManyToOne(targetEntity="Website\Bundle\DeviceBundle\Entity\Users")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="user", referencedColumnName="id")
* })
*/
private $user;
and the error it comes when I GET the doneAction() url, is this
A storage for model Website\DeviceBundle\Entity\PaymentDetails was not registered. There are storages for next models: Website\Bundle\DeviceBundle\Entity\PaymentDetails.
any helps or suggestions?
thank you in advance
just changed this line
$storage = $this->get('payum')->getStorage('Website\DeviceBundle\Entity\PaymentDetails');
into
$storage = $this->get('payum')->getStorage('Website\Bundle\DeviceBundle\Entity\PaymentDetails');
and now it works.

Symfony2 auto generating entities error.

i have two tables news and news_category. for that i have created two mapping class using symfony command 'doctrine:mapping:convert'. the two file as bellow.
news.orm.yml.
News:
type: entity
table: news
fields:
newsId:
id: true
type: integer
unsigned: false
nullable: false
column: news_id
generator:
strategy: IDENTITY
newsTitle:
type: string
length: 255
fixed: false
nullable: false
column: news_title
newsDescription:
type: text
nullable: false
column: news_description
newsStatus:
type: string
length: 255
fixed: false
nullable: false
column: news_status
createdAt:
type: date
nullable: false
column: created_at
manyToOne:
category:
targetEntity: NewsCategory
cascade: { }
mappedBy: null
inversedBy: null
joinColumns:
category_id:
referencedColumnName: category_id
orphanRemoval: false
lifecycleCallbacks: { }
2). NewCategory.orm.yml
NewsCategory:
type: entity
table: news_category
fields:
categoryId:
id: true
type: integer
unsigned: false
nullable: false
column: category_id
generator:
strategy: IDENTITY
categoryTitle:
type: string
length: 255
fixed: false
nullable: false
column: category_title
categoryDescription:
type: text
nullable: false
column: category_description
lifecycleCallbacks: { }
after that i have used the another symfony command "doctrine:mapping:import" using this i have again generate two file in Entity folder News.php and NewsCategory.php
which is as bellow.
1) news.php
<?php
namespace Admin\NewsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* News
*
* #ORM\Table(name="news")
* #ORM\Entity
*/
class News
{
/**
* #var integer
*
* #ORM\Column(name="news_id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $newsId;
/**
* #var string
*
* #ORM\Column(name="news_title", type="string", length=255, nullable=false)
*/
private $newsTitle;
/**
* #var string
*
* #ORM\Column(name="news_description", type="text", nullable=false)
*/
private $newsDescription;
/**
* #var string
*
* #ORM\Column(name="news_status", type="string", length=255, nullable=false)
*/
private $newsStatus;
/**
* #var \DateTime
*
* #ORM\Column(name="created_at", type="date", nullable=false)
*/
private $createdAt;
/**
* #var \NewsCategory
*
* #ORM\ManyToOne(targetEntity="NewsCategory")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="category_id", referencedColumnName="category_id")
* })
*/
private $category;
}
And, 2) NewCategory.php
namespace Admin\NewsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* NewsCategory
*
* #ORM\Table(name="news_category")
* #ORM\Entity
*/
class NewsCategory
{
/**
* #var integer
*
* #ORM\Column(name="category_id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $categoryId;
/**
* #var string
*
* #ORM\Column(name="category_title", type="string", length=255, nullable=false)
*/
private $categoryTitle;
/**
* #var string
*
* #ORM\Column(name="category_description", type="text", nullable=false)
*/
private $categoryDescription;
}
the problem is now when i am creating the Entities using the "doctrine:generate:entities"
it is giving me the following error.
D:\wamp\www\Symfony>php app/console doctrine:generate:entities AdminNewsBundle
Generating entities for bundle "AdminNewsBundle"
[Doctrine\Common\Persistence\Mapping\MappingException]
Invalid mapping file 'Admin.NewsBundle.Entity.News.orm.yml' for class 'Admi
n\NewsBundle\Entity\News'.
doctrine:generate:entities [--path="..."] [--no-backup] name
sorry for poor english please help me out come from this problem as i am new to symfony2
Try:
1) php app/console doctrine:mapping:convert yml ./src/Admin/NewsBundle/Resources/config/doctrine/metadata/orm --from-database --force --namespace="Admin\\NewsBundle\\Entity\\"
for Linux namespace="Admin\\NewsBundle\\Entity\\", for Win probably namespace="Admin\NewsBundle\Entity\\"
Watch that mapping is in right place, has correct names and correct syntax.
2) php app/console doctrine:mapping:import AdminNewsBundle annotation
3) php app/console doctrine:generate:entities AdminNewsBundle
Try replacing the first line of YML with the entity name with naspace
Admin\NewsBundle\Entity\News:
for exemple.

Resources