Duplicate definition of column 'urbanization' on entity - entity-framework

I'm working with FOSUserBundle and I need to build Users Profile. This is what I did:
Create the User class and extends from BaseUser as FOSUser docs said
namespace Sunahip\UserBundle\Entity;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity
* #ORM\Table(name="fos_user")
*/
class User extends BaseUser
{
/**
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* #ORM\OneToOne(targetEntity="Profile", mappedBy="user")
*/
protected $profile;
/**
* #ORM\ManyToMany(targetEntity="Sunahip\UserBundle\Entity\Group")
* #ORM\JoinTable(name="fos_user_user_group",
* joinColumns={#ORM\JoinColumn(name="user_id", referencedColumnName="id")},
* inverseJoinColumns={#ORM\JoinColumn(name="group_id", referencedColumnName="id")}
* )
*/
protected $groups;
}
Create a Profile entity
namespace Sunahip\UserBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\User as BaseUser;
/**
* #ORM\Entity
* #ORM\Table(name="profile")
*/
class Profile extends BaseUser
{
/**
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* #ORM\Id
* #ORM\OneToOne(targetEntity="User", inversedBy="profile")
* #ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
protected $user;
/**
* #ORM\Column(name="register_type", type="smallint", length=1)
*/
protected $register_type;
/**
* #ORM\Column(name="rif", type="string", length=25)
*/
protected $rif;
/**
* #ORM\Column(name="ci", type="string", length=25)
*/
protected $ci;
/**
* #ORM\Column(name="firstname", type="string", length=25)
*/
protected $firstname;
/**
* #ORM\Column(name="lastname", type="string", length=25)
*/
protected $lastname;
/**
* #ORM\Column(name="state", type="string", length=150)
*/
protected $state;
/**
* #ORM\Column(name="city", type="string", length=150)
*/
protected $city;
/**
* #ORM\Column(name="town", type="string", length=150)
*/
protected $town;
/**
* #ORM\Column(name="urbanization", type="string", length=150)
*/
protected $urbanization;
/**
* #ORM\Column(name="urbanization", type="string", length=150)
*/
protected $street;
/**
* #ORM\Column(name="aparment", type="string", length=150)
*/
protected $aparment;
/**
* #ORM\Column(name="aparment_no", type="string", length=150)
*/
protected $aparment_no;
/**
* #ORM\Column(name="reference", type="string", length=250)
*/
protected $reference;
/**
* #ORM\Column(name="zipcode", type="string", length=250)
*/
protected $zipcode;
/**
* #ORM\Column(name="fax", type="string", length=250)
*/
protected $fax;
/**
* #ORM\Column(name="local_phone", type="string", length=250)
*/
protected $local_phone;
/**
* #ORM\Column(name="movil_phone", type="string", length=250)
*/
protected $movil_phone;
/**
* #ORM\Column(name="alt_email", type="string", length=250)
*/
protected $alt_email;
/**
* #ORM\Column(name="alt_email", type="string", length=250)
*/
protected $website;
public function getId()
{
return $this->id;
}
public function setUser(User $user)
{
$this->user = $user;
}
public function getUser()
{
return $this->user;
}
public function setRegisterType($register_type)
{
$this->register_type = $register_type;
}
public function getRegisterType()
{
return $this->register_type;
}
public function setRif($rif)
{
$this->rif = $rif;
}
public function getRif()
{
return $this->rif;
}
public function setCI($ci)
{
$this->ci = $ci;
}
public function getCI()
{
return $this->ci;
}
public function setFirstname($firstname)
{
$this->firstname = $firstname;
}
public function getFirstname()
{
return $this->firstname;
}
public function setLastname($lastname)
{
$this->lastname = $lastname;
}
public function getLastname()
{
return $this->lastname;
}
public function setState($state)
{
$this->state = $state;
}
public function getState()
{
return $this->state;
}
public function setCity($city)
{
$this->city = $city;
}
public function getCity()
{
return $this->city;
}
public function setTown($town)
{
$this->town = $town;
}
public function getTown()
{
return $this->town;
}
public function setUrbanization($urbanization)
{
$this->urbanization = $urbanization;
}
public function getUrbanization()
{
return $this->urbanization;
}
public function setStreet($street)
{
$this->street = $street;
}
public function getStreet()
{
return $this->street;
}
public function setAparment($aparment)
{
$this->aparment = $aparment;
}
public function getAparment()
{
return $this->aparment;
}
public function setAparmentNo($aparment_no)
{
$this->aparment_no = $aparment_no;
}
public function getAparmentNo()
{
return $this->aparment_no;
}
public function setReference($reference)
{
$this->reference = $reference;
}
public function getReference()
{
return $this->reference;
}
public function setZipcode($zipcode)
{
$this->zipcode = $zipcode;
}
public function getZipcode()
{
return $this->zipcode;
}
public function setFax($fax)
{
$this->fax = $fax;
}
public function getFax()
{
return $this->fax;
}
public function setLocalPhone($local_phone)
{
$this->local_phone = $local_phone;
}
public function getLocalPhone()
{
return $this->local_phone;
}
public function setMovilPhone($movil_phone)
{
$this->movil_phone = $movil_phone;
}
public function getMovilPhone()
{
return $this->movil_phone;
}
public function setAltEmail($alt_email)
{
$this->alt_email = $alt_email;
}
public function getAltEmail()
{
return $this->alt_email;
}
public function setWebsite($website)
{
$this->website = $website;
}
public function getWebsite()
{
return $this->website;
}
}
Now, I'm trying to validate that entities by running the command doctrine:schema:validate and I get this error:
[Doctrine\ORM\Mapping\MappingException] Duplicate definition of
column 'urbanization' on entity 'Sunahip\UserBundle\Entity\Profile' in
a field or discriminator column mapping.
My questions:
I don't know what is wrong and also don't know what the error means is the first time I got this error.
I don't know if I'm building users profiles in the right way I mean if I should extends from BaseUser or from User
Can I give some help here? Advices? Ideas?

You have (had) basically two probles here:
Duplicated urbanization column name somewhere there which needs to be removed. Only one column with the same name is allowed
Duplicated #ORM\Id annotation in your Profile entity. Remove one from $user because it is not your Id

Related

Trying to insert data ManyToOne FOSRestBundle

I'm trying to creating an API REST with the bundle FOSRestBundle (SF5).
I've an entity "Categorie" which can have an parent "Categorie".
Here is the entity :
<?php
namespace App\Entity\Main;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation\Expose;
use JMS\Serializer\Annotation\ExclusionPolicy;
use Symfony\Component\Validator\Constraints as Assert;
/**
* #ORM\Entity(repositoryClass="App\Repository\CategorieRepository")
* #ORM\Table(name="categorie")
* #ExclusionPolicy("all")
*/
class Categorie
{
/**
* #ORM\Id()
* #ORM\GeneratedValue()
* #Expose
* #ORM\Column(type="integer")
*/
private $id;
/**
* #var string
* #Assert\NotBlank()
* #Expose
* #ORM\Column(type="string", length=255)
*/
private $libelle;
/**
* #var string
* #Assert\NotBlank()
* #Expose
* #ORM\Column(type="string", length=255)
*/
private $icone;
/**
* #var Categorie
* #ORM\ManyToOne(targetEntity="App\Entity\Main\Categorie", inversedBy="categories", cascade={"all"}, fetch="EAGER")
* #ORM\JoinColumn(name="categorie_parent_id", referencedColumnName="id", nullable=true)
*/
private $categorieParent;
/**
* #var ArrayCollection
* #ORM\OneToMany(targetEntity="App\Entity\Main\Categorie", mappedBy="categorieParent")
*/
private $categories;
/**
* #var ArrayCollection
* #ORM\OneToMany(targetEntity="App\Entity\Main\Produit", mappedBy="categorie")
*/
private $produits;
public function __construct()
{
$this->produits = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getLibelle(): ?string
{
return $this->libelle;
}
public function setLibelle(string $libelle): self
{
$this->libelle = $libelle;
return $this;
}
public function getIcone(): ?string
{
return $this->icone;
}
public function setIcone(string $icone): self
{
$this->icone = $icone;
return $this;
}
public function setCategorieParent(Categorie $categorieParent): self
{
$this->categorieParent = $categorieParent;
return $this;
}
public function getCategorieParent(Categorie $categorieParent)
{
return $this->categorieParent;
}
}
Here is my action in controller :
/**
* #Rest\View(statusCode=Response::HTTP_CREATED)
* #Rest\Post("/api/{_locale}/categorie/create", name="api_categorie_create")
* #ParamConverter("categorie", converter="fos_rest.request_body")
* #IsGranted("ROLE_SUPER_ADMIN")
* #return Categorie|View
*/
public function create(Categorie $categorie, ConstraintViolationList $violations)
{
if (count($violations)) {
return $this->view($violations, Response::HTTP_BAD_REQUEST);
}
$em = $this->getDoctrine()->getManager('main');
$em->persist($categorie);
$em->flush();
return $categorie;
}
When I use postman to insert data with this content :
{
"libelle":"Blonde",
"icone":"blonde.png",
"categorieParent.id": 1
}
"libelle" and "icone" are inserted but "categorieParent" wasn't set.
I've try :
{
"libelle":"Blonde",
"icone":"blonde.png",
"categorieParent": 1
}
{
"libelle":"Blonde",
"icone":"blonde.png",
"categorieParent": {
"id": 1
}
}
For each try, I set id with number and string.
And anything doesn't work.
Thx for help :) !
CategorieParent will only accept a Categorie entity; libelle and icone work because they are simple strings. You should use the passed integer to fetch the Entity, then save the values.

Relationship between two entities

I have a trouble and I need your assistance. Now I create two entities :
Partner
PartnerMedia
Partner entity contains all information about my partners and the other entity, have relationship with Partner and Sonata Media Entity.
There is what contains my partner entity :
<?php
namespace AppBundle\Entity;
use AppBundle\Entity\CMS\Block;
use AppBundle\Entity\SuperClass\SortableTranslatableEntity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Sonata\MediaBundle\Model\Media;
use Doctrine\Common\Collections\ArrayCollection;
use Sonata\TranslationBundle\Model\Gedmo\TranslatableInterface;
/**
* Partner.
*
* #ORM\Table("partner")
* #ORM\Entity
*/
class Partner extends SortableTranslatableEntity implements TranslatableInterface
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="libelle", type="string", length=60)
* #Gedmo\Translatable
*/
private $libelle;
/**
* #var string
*
* #ORM\Column(name="mea", type="boolean")
*/
private $mea;
/**
* #ORM\OneToMany(targetEntity="\AppBundle\Entity\Media\PartnerMedia", mappedBy="partner", cascade={"persist"}, orphanRemoval=true)
* #ORM\OrderBy({"position" = "ASC"})
*/
private $medias;
/**
* #ORM\Column(type="string", name="url", nullable=true)
* #Gedmo\Translatable
*/
private $url;
/**
* #ORM\ManyToOne(targetEntity="\AppBundle\Entity\CMS\Block", inversedBy="block")
*/
private $block;
public function __construct()
{
$this->medias = new ArrayCollection();
}
public function setTranslatableLocale($locale)
{
$this->locale = $locale;
}
public function getContextName()
{
return 'partner';
}
public function __toString()
{
return $this->getId() ? (string) $this->getLibelle() : '-';
}
public function firstPhoto()
{
if ($this->getMedias() && $this->getMedias()->count()) {
return $this->getMedias()->first()->getMedia();
}
}
public function getId()
{
return $this->id;
}
public function getLibelle()
{
return $this->libelle;
}
/**
* Add medias.
*
* #param PartnerMedia $media
*
* #return PartnerMedia
*/
public function addMedias(PartnerMedia $media)
{
$media->setPartner($this);
$this->medias[] = $media;
return $this;
}
/**
* Remove medias.
*
* #param PartnerMedia $media
*/
public function removeMedia(PartnerMedia $media)
{
$this->medias->removeElement($media);
}
public function getMedias()
{
return $this->medias;
}
public function getUrl()
{
return $this->url;
}
/**
* Get page.
*
* #return \AppBundle\Entity\CMS\Block
*/
public function getBlock()
{
return $this->block;
}
public function setId($id)
{
$this->id = $id;
}
public function setLibelle($libelle)
{
$this->libelle = $libelle;
}
public function setUrl($url)
{
$this->url = $url;
}
/**
* Set page.
*
* #param \AppBundle\Entity\CMS\Block $block
* #return Partner
*/
public function setBlock(Block $block = null)
{
$this->block = $block;
return $this;
}
/**
* Set mea
*
* #param boolean $mea
* #return Partner
*/
public function setMea($mea)
{
$this->mea = $mea;
return $this;
}
/**
* Get mea
*
* #return boolean
*/
public function getMea()
{
return $this->mea;
}
/**
* #param mixed $medias
*/
public function setMedias($medias)
{
$this->medias = $medias;
}
}
and what contains PartnerMedia entity :
<?php
/**
* PartnerMedia
*
* #ORM\Table()
* #ORM\Entity
*/
class PartnerMedia extends SortableEntity
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\ManyToOne(targetEntity="\Application\Sonata\MediaBundle\Entity\Media")
*/
private $medias;
/**
* #ORM\ManyToOne(targetEntity="\AppBundle\Entity\Partner", inversedBy="partner")
*
* #Gedmo\SortableGroup
*/
private $partner;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set medias
*
* #param Media $medias
* #return PartnerMedia
*/
public function setMedias(Media $medias = null)
{
$this->medias = $medias;
return $this;
}
/**
* Get medias
*
* #return Media
*/
public function getMedias()
{
return $this->medias;
}
/**
* Set Partner
*
* #param Partner $partner
* #return PartnerMedia
*/
public function setPartner(Partner $partner = null)
{
$this->partner = $partner;
return $this;
}
/**
* Get Partner
*
* #return Partner
*/
public function getPartner()
{
return $this->partner;
}
public function getContextName()
{
return 'partner_media';
}
public function __construct()
{
$this->medias = new ArrayCollection();
}
}
Now when I tried to create a new partner, I receive that exception :
The current field medias is not linked to an admin. Please create one for the target entity : AppBundle\Entity\Media\PartnerMedia
I need your assistance please and thanks
The error message you describe sounds more like a Sonata Admin error.
One of the things about sonata admin is that when you are creating links between entities, you need to have admin classes built for both entity classes.
More than likely, you're trying to test your code before completely implementing the admins necessary to do so.

Zend2 Framework - Doctrine ORM giving Mapping Exception

I'm trying to use Doctrine 2 ORM for one of my Zend2 applications. I did the setup within the application using Doctrine modules with the help of composer.
I'm able to persist the data to the database, but when i make a find() call on the object manager it is giving me a Mapping Exception, with the following message.
Doctrine\Common\Persistence\Mapping\MappingException
File:
/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/MappingException.php:96
Message:
Class 'User' does not exist
Below are the Doctrine settings added under the Application module config file
'driver' => array(
'application_entities' => array(
'class' =>'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(__DIR__ . '/../src/Application/Entity')
),
'orm_default' => array(
'drivers' => array(
'Application\Entity' => 'application_entities'
)
)
)
),
This is the User Entity created under Application\src\Entity folder
<?php
namespace Application\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity
*/
class User {
/**
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="NONE")
* #var int
*/
protected $user_id;
/**
* #ORM\Column(type="integer")
* #var int
*/
protected $network_id;
/**
* #ORM\Column(type="string", length=64)
* #var string
*/
protected $network_name;
/**
* #ORM\Column(type="string", length=64)
* #var string
*/
protected $job_title;
/**
* #ORM\Column(type="string", length=64)
* #var string
*/
protected $location;
/**
* #ORM\Column(type="string", length=64)
* #var string
*/
protected $first_name;
/**
* #ORM\Column(type="string", length=64)
* #var string
*/
protected $last_name;
/**
* #ORM\Column(type="string", length=255)
* #var string
*/
protected $url;
/**
* #ORM\Column(type="string", length=255)
* #var string
*/
protected $img_url;
/**
* #ORM\Column(type="string", length=255)
* #var string
*/
protected $department;
/**
* #ORM\Column(type="string", length=255)
* #var string
*/
protected $email_address;
/**
* #ORM\Column(type="boolean")
* #var string
*/
protected $verified;
/**
* #return the int
*/
public function getUserId() {
return $this->user_id;
}
/**
* #param int $user_id
*/
public function setUserId($user_id) {
$this->user_id = $user_id;
return $this;
}
/**
* #return the int
*/
public function getNetworkId() {
return $this->network_id;
}
/**
* #param int $network_id
*/
public function setNetworkId($network_id) {
$this->network_id = $network_id;
return $this;
}
/**
* #return the string
*/
public function getNetworkName() {
return $this->network_name;
}
/**
* #param string $network_name
*/
public function setNetworkName($network_name) {
$this->network_name = $network_name;
return $this;
}
/**
* #return the string
*/
public function getJobTitle() {
return $this->job_title;
}
/**
* #param string $job_title
*/
public function setJobTitle($job_title) {
$this->job_title = $job_title;
return $this;
}
/**
* #return the string
*/
public function getLocation() {
return $this->location;
}
/**
* #param string $location
*/
public function setLocation($location) {
$this->location = $location;
return $this;
}
/**
* #return the string
*/
public function getFirstName() {
return $this->first_name;
}
/**
* #param string $first_name
*/
public function setFirstName($first_name) {
$this->first_name = $first_name;
return $this;
}
/**
* #return the string
*/
public function getLastName() {
return $this->last_name;
}
/**
* #param string $last_name
*/
public function setLastName($last_name) {
$this->last_name = $last_name;
return $this;
}
/**
* #return the string
*/
public function getUrl() {
return $this->url;
}
/**
* #param string $url
*/
public function setUrl($url) {
$this->url = $url;
return $this;
}
/**
* #return the string
*/
public function getImgUrl() {
return $this->img_url;
}
/**
* #param string $img_url
*/
public function setImgUrl($img_url) {
$this->img_url = $img_url;
return $this;
}
/**
* #return the string
*/
public function getDepartment() {
return $this->department;
}
/**
* #param string $department
*/
public function setDepartment($department) {
$this->department = $department;
return $this;
}
/**
* #return the string
*/
public function getEmailAddress() {
return $this->email_address;
}
/**
* #param string $email_address
*/
public function setEmailAddress($email_address) {
$this->email_address = $email_address;
return $this;
}
/**
* #return the boolean
*/
public function getVerified() {
return $this->verified;
}
/**
* #param boolean $verified
*/
public function setVerified($verfied) {
$this->verified = $verfied;
return $this;
}
}
Now, when I do persist operation on the above entity from Application module's IndexController, it is working fine. But when I do the find operation using the same object mapper in the same IndexController, it is giving the mapping exception.
Below is how I'm doing this:
$objectManager = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');
$objectManager->persist($user);
$objectManager->flush();
$user = $objectManager->find('User', $uniqueID);
Can anyone help me with this issue??
Regards.
Your entity is not called User but Application\Entity\User. So replace this line:
$user = $objectManager->find('User', $uniqueID);
With this:
$user = $objectManager->find('Application\Entity\User', $uniqueID);

Doctrine 2 under Zend error: Class Entities\X has no association named Entities\Y

I have a rather strange problem. I'm using Doctrine 2 under Zend Framework 1.11. I have a database called "Sessions", which are training sessions for students. Each session has an associated note, called a SOAPE note. Edit: I am now including both of the entities in question.
Sessions:
use Doctrine\ORM\Mapping as ORM;
/**
* #Entity(repositoryClass="Repositories\Sessions")
* #Table(name="Sessions")
*/
class Sessions
{
/**
* #var integer Id
*
* #Id #Column(type="integer")
* #GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* #var integer $schId
*
* #Column(name="schId", type="integer", nullable=false)
*/
protected $schId;
/**
* #var integer $stdId
*
* #Column(name="stdId", type="integer", nullable=false)
*/
protected $stdId;
/**
* #var integer $trainerPsnId
*
* #Column(name="trainerPsnId", type="integer", nullable=false)
*/
protected $trainerPsnId;
/**
* #var boolean $isLegacy
*
* #Column(name="isLegacy", type="boolean", nullable=false)
*/
protected $isLegacy;
/**
* #var float $charge
*
* #Column(name="charge", type="float", nullable=false)
*/
protected $charge;
/**
* #var float $trainerPay
*
* #Column(name="trainerPay", type="float", nullable=false)
*/
protected $trainerPay;
/**
* #var integer $modeId
*
* #Column(name="modeId", type="integer", nullable=false)
*/
protected $modeId;
/**
* #var text $notes
*
* #Column(name="notes", type="text", nullable=true)
*/
protected $notes;
/**
* #var string $twitterNote
*
* #Column(name="twitterNote", type="string", length=20, nullable=true)
*/
protected $twitterNote;
// ASSOCIATIONS
/**
* #OneToOne(targetEntity="Schedule", inversedBy="session")
* #JoinColumn(name="schId", referencedColumnName="id")
*/
protected $schedule;
/**
* #OneToOne(targetEntity="SnSoapeNotes", mappedBy="session")
* #JoinColumn(name="id", referencedColumnName="snId")
*/
protected $soapeNote;
/**
* #ManyToOne(targetEntity="Students")
* #JoinColumn(name="stdId", referencedColumnName="id")
*/
protected $student;
/**
* #ManyToOne(targetEntity="Personnel", inversedBy="sessions")
* #JoinColumn(name="trainerPsnId", referencedColumnName="id")
*/
protected $trainer;
// Getters and Setters
public function getId()
{
return $this->id;
}
public function getSchId()
{
return $this->schId;
}
public function setSchId($schId)
{
$this->schId = $schId;
}
public function getStdId()
{
return $this->stdId;
}
public function setStdId($stdId)
{
$this->stdId = $stdId;
}
public function getTrainerPsnId()
{
return $this->trainerPsnId;
}
public function setTrainerPsnId($trainerPsnId)
{
$this->stdId = $trainerPsnId;
}
public function getIsLegacy()
{
return $this->isLegacy;
}
public function setIsLegacy($isLegacy)
{
$this->isLegacy = $isLegacy;
}
public function getCharge()
{
return $this->charge;
}
public function setCharge($charge)
{
$this->charge = $charge;
}
public function getTrainerPay()
{
return $this->trainerPay;
}
public function setTrainerPay($trainerPay)
{
$this->trainerPay = $trainerPay;
}
public function getModeId()
{
return $this->modeId;
}
public function setModeId($modeId)
{
$this->modeId = $modeId;
}
public function getNotes()
{
return $this->notes;
}
public function setNotes($notes)
{
$this->notes = $notes;
}
public function getTwitterNote()
{
return $this->twitterNote;
}
public function setTwitterNote($twitterNote)
{
$this->twitterNote = $twitterNote;
}
// Foreign Data
public function getSchedule()
{
return $this->schedule;
}
public function getStudent()
{
return $this->student;
}
public function getTrainer()
{
return $this->trainer;
}
public function getSoapeNote()
{
return $this->soapeNote;
}
}
SnSoapeNotes:
namespace Entities;
use Doctrine\Mapping as ORM;
/**
* SnSoapeNotes
*
* #Table(name="SnSoapeNotes")
* #Entity(repositoryClass="Repositories\SnSoapeNotes")
*/
class SnSoapeNotes
{
/**
* #var integer Id
*
* #Id #Column(type="integer")
* #GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* #var integer $mental
*
* #Column(name="mental", type="integer", nullable=false)
*/
private $mental;
/**
* #var integer $physical
*
* #Column(name="physical", type="integer", nullable=false)
*/
private $physical;
/**
* #var text $subjective
*
* #Column(name="subjective", type="text", nullable=false)
*/
private $subjective;
/**
* #var text $objective
*
* #Column(name="objective", type="text", nullable=false)
*/
private $objective;
/**
* #var text $plan
*
* #Column(name="plan", type="text", nullable=false)
*/
private $plan;
/**
* #var text $action
*
* #Column(name="action", type="text", nullable=false)
*/
private $action;
/**
* #var text $education
*
* #Column(name="education", type="text", nullable=false)
*/
private $education;
/**
* #var text $warning
*
* #Column(name="warning", type="text", nullable=true)
*/
private $warning;
/**
* #var text $incident
*
* #Column(name="incident", type="text", nullable=true)
*/
private $incident;
/**
* #var text $technical
*
* #Column(name="technical", type="text", nullable=true)
*/
private $technical;
// ASSOCIATIONS
/**
* #Var Sessions $sessions
*
* #Column(name="snId", type="integer", nullable=false)
* #OneToOne(targetEntity="Sessions", inversedBy="soapeNote")
* #JoinColumn(name="snId", referencedColumnName="id")
*/
protected $sessions;
// Getters and Setters
public function getSnId()
{
return $this->snId;
}
public function setSnId($snId)
{
$this->snId = $snId;
}
public function getMental()
{
return $this->mental;
}
public function setMental($mental)
{
$this->mental = $mental;
}
public function getPhysical()
{
return $this->physical;
}
public function setPhysical($physical)
{
$this->physical = $physical;
}
public function getSubjective()
{
return $this->subjective;
}
public function setSubjective($subjective)
{
$this->subjective = $subjective;
}
public function getObjective()
{
return $this->objective;
}
public function setObjective($objective)
{
$this->objective = $objective;
}
public function getPlan()
{
return $this->plan;
}
public function setPlan($plan)
{
$this->plan = $plan;
}
public function getAction()
{
return $this->action;
}
public function setAction($action)
{
$this->action = $action;
}
public function getEducation()
{
return $this->education;
}
public function setEducation($education)
{
$this->education = $education;
}
public function getWarning()
{
return $this->warning;
}
public function setWarning($warning)
{
$this->warning = $warning;
}
public function getIncident()
{
return $this->incident;
}
public function setIncident($incident)
{
$this->incident = $incident;
}
public function getTechnical()
{
return $this->technical;
}
public function setTechnical($technical)
{
$this->technical = $technical;
}
public function getSession()
{
return $this->session;
}
// A quick way to make sure the soape note has been completed.
// Note that objective is left out here because it can be
// filled out beforehand
public function getIsComplete()
{
return !empty($this->subjective)
&& !empty($this->action)
&& !empty($this->plan)
&& !empty($this->education);
}
}
When calling $em->getRepository('Entities\Sessions')->findOneBy('id'), everything works fine--I get the session and its accompanying SOAPE note. Ditto for other associated tables' data.
But now I am trying to write a custom repository to get the notes prior to this session. The function is as follows:
<?php
namespace Repositories;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query\ResultSetMapping;
use Doctrine\DBAL\Types\Type;
/**
* Sessions
*/
class Sessions extends EntityRepository
{
public function getPastSoapeNotes($params) {
$studentId = $params['studentId'];
$latestSession = $params['snDatetime'] ?: date('Y-m-d H:i');
$qb = $this->_em->createQueryBuilder();
$qb->select('n.subjective, n.objective, n.plan, n.action, n.education')
->from('Entities\Sessions', 'sn')
->innerJoin('sn.Entities\SnSoapeNotes', 'n');
return $qb->getQuery()->getResult();
}
}
When I call this, I get the following error:
[Semantical Error] line 0, col 126 near 'n': Error: Class Entities\Sessions has no association named Entities\SnSoapeNotes
I have also tried using the "mappedBy" and "inersedBy" annotations in every possible combination, but to no avail; Doctrine can't seem to find the association. I am at a complete loss as to what is going on.
I figured out what I did wrong. In the join statement, I used 'sn.Entities\SnSoapeNotes' when I should have used just 'soapeNote', which is the property in the Sessions class, not the table name itself.

How to integrate i18n doctrine translation into zend framework?

Say I have an simple entity UserType. I would like usertype to be available in various languages because it will appear in drop-downs in the UI. How should I set i18n up to work in my project? It was not clear in the docs.
<?php
namespace Entities;
/**
* #Entity (repositoryClass="Repositories\UserType")
* #Table(name="usertypes")
* #HasLifecycleCallbacks
*/
class UserType {
/**
* #Id #Column(type="integer")
* #GeneratedValue(strategy="AUTO")
*/
private $id;
/** #Column(type="string", length=30,unique=TRUE) */
private $usertype;
/** #Column(type="boolean") */
private $active;
public function __construct() {
$this->active = true;
}
/**
* #return the $id
*/
public function getId() {
return $this->id;
}
/**
* #return the $usertype
*/
public function getUserType() {
return $this->usertype;
}
/**
* #return the $active
*/
public function getActive() {
return $this->active;
}
/**
* #param field_type $usertype
*/
public function setUsertype($usertype) {
$this->usertype = $usertype;
}
/**
* #param field_type $active
*/
public function setActive($active) {
$this->active = $active;
}
}
You simply add "#gedmo:Translatable" in your comment block for translable fields
<?php
namespace Entities;
/**
* #Entity (repositoryClass="Repositories\UserType")
* #Table(name="usertypes")
* #HasLifecycleCallbacks
*/
class UserType {
/**
* #Id #Column(type="integer")
* #GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #gedmo:Translatable
* #Column(type="string", length=30,unique=TRUE)
*/
private $usertype;
/** #Column(type="boolean") */
private $active;
/**
* #gedmo:Locale
*/
private $locale;
public function __construct() {
$this->active = true;
}
/**
* #return the $id
*/
public function getId() {
return $this->id;
}
/**
* #return the $usertype
*/
public function getUserType() {
return $this->usertype;
}
/**
* #return the $active
*/
public function getActive() {
return $this->active;
}
/**
* #param field_type $usertype
*/
public function setUsertype($usertype) {
$this->usertype = $usertype;
}
/**
* #param field_type $active
*/
public function setActive($active) {
$this->active = $active;
}
public function setTranslatableLocale($locale)
{
$this->locale = $locale;
}
}