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;
}
}
Related
I'm trying to get INSERT values from a form into DB, one of my form fields is brand_id which is returning NULL upon submission.
There are two entities having Many to One relationship
Brand
id
name
Model
id
brand_id (FK)
name
image_url
comment
All fields return a value but the brand_id returns NULL
Code and Entitys are as follows:
brand Entity:
<?php
// src/coreBundle/Entity/Brand.php
namespace coreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use coreBundle\Entity\Model;
use Doctrine\Common\Collections\ArrayCollection;
/**
*#ORM\Entity
*#ORM\Table(name="brand")
*/
class brand
{
/**
* #var int
* #ORM\Id
* #ORM\Column(name="id", type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
public $id;
/**
*#ORM\Column(type="string", length=100)
*/
private $name;
/**
*#ORM\OneToMany(targetEntity="model", mappedBy="brands")
*/
protected $models;
public function __construct()
{
$this->models = new ArrayCollection();
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* #param string $name
*
* #return brand
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* Add model
*
* #param \coreBundle\Entity\model $model
*
* #return brand
*/
public function addModel(\coreBundle\Entity\model $model)
{
$this->models[] = $model;
return $this;
}
/**
* Remove model
*
* #param \coreBundle\Entity\model $model
*/
public function removeModel(\coreBundle\Entity\model $model)
{
$this->models->removeElement($model);
}
/**
* Get models
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getModels()
{
return $this->models;
}
}
model Entity :
<?php
// src/coreBundle/Entity/Model.php
namespace coreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use coreBundle\Entity\Brand;
/**
*#ORM\Entity
*#ORM\Table(name="model")
*/
class model
{
/**
* #var int
* #ORM\Id
* #ORM\Column(name="id", type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
public $id;
/**
*#ORM\Column(type="integer")
*/
public $brand_id;
/**
*#ORM\Column(type="string", length=100)
*/
private $name;
/**
*#ORM\Column(type="string", length=100)
*/
private $image_url;
/**
*#ORM\Column(type="string", length=200)
*/
private $comment;
/**
*#ORM\ManyToOne(targetEntity="brand", inversedBy="models")
*#ORM\JoinColumn(name="brand_id", referencedColumnName="id")
*/
protected $brands;
/**
* #ORM\OneToOne(targetEntity="model_item", mappedBy="models")
*/
private $model_items;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set brandId
*
* #param integer $brandId
*
* #return model
*/
public function setBrandId($brandId)
{
$this->brand_id = $brandId;
return $this;
}
/**
* Get brandId
*
* #return integer
*/
public function getBrandId()
{
return $this->brand_id;
}
/**
* Set name
*
* #param string $name
*
* #return model
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* Set imageUrl
*
* #param string $imageUrl
*
* #return model
*/
public function setImageUrl($imageUrl)
{
$this->image_url = $imageUrl;
return $this;
}
/**
* Get imageUrl
*
* #return string
*/
public function getImageUrl()
{
return $this->image_url;
}
/**
* Set comment
*
* #param string $comment
*
* #return model
*/
public function setComment($comment)
{
$this->comment = $comment;
return $this;
}
/**
* Get comment
*
* #return string
*/
public function getComment()
{
return $this->comment;
}
/**
* Set brands
*
* #param \coreBundle\Entity\brand $brands
*
* #return model
*/
public function setBrands(\coreBundle\Entity\brand $brands = null)
{
$this->brands = $brands;
return $this;
}
/**
* Get brands
*
* #return \coreBundle\Entity\brand
*/
public function getBrands()
{
return $this->brands;
}
}
My Controller Code:
public function newModelAction(Request $request)
{
$product = $this->getDoctrine()
->getRepository('coreBundle:brand')
->findAll();
if (!$product) {
throw $this->createNotFoundException(
'No product found for id '.$productId
);
}
$model = new model();
$form = $this->createFormBuilder($model)
->add('brand_id',TextType::class,array('label'=>'Brand Id'))
->add('name',TextType::class,array('label'=>'Model Name'))
->add('comment',TextType::class,array('label'=>'Comments'))
->add('image_url',TextType::class,array('label'=>'Image URL'))
->add('save',SubmitType::class, array('label'=>'Add Model'))
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($model);
$em->flush();
return $this->render('coreBundle:layouts:newItem.html.twig',
array('form'=>$form->createView(),));
}
// ... do something, like pass the $product object into a template
return $this->render('coreBundle:layouts:newModel.html.twig',
array('form'=>$form->createView(),));
}
Try to remove this:
*#ORM\Column(type="integer")
*/
public $brand_id;
Because you have already the field for brands in this point:
/**
*#ORM\ManyToOne(targetEntity="brand", inversedBy="models")
*#ORM\JoinColumn(name="brand_id", referencedColumnName="id")
*/
protected $brands;
You need also to remove getter and seeter of brandId and remove brand_id from the form and adding this for example:
->add('brand', EntityType::class, array(
// query choices from this entity
'class' => 'AppBundle:Brand',
))
Try this
/**
*#ORM\ManyToOne(targetEntity="brand")
*#ORM\JoinColumn(nullable=false)
*/
protected $brands;
i have created a new model which have an attribute "image" , i have generated the CRUD using the SyliusResourcesBundle ,
what i'm trying to achieve is to display an image in the edit form type , how can i do that ? thx in advance
my form type :
<?php
namespace AppBundle\Form\Type;
use Sylius\Bundle\ResourceBundle\Form\Type\DefaultResourceType as BaseSliderType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class SliderType extends AbstractType
{
/**
* {#inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
parent::buildForm($builder, $options);
$builder->add('lib','text'
);$builder->add('title','text'
);
$builder->add('description','text'
);
$builder->add('file',FileType::class
);
}
public function getName()
{
return 'app_slider';
}
}
?>
my model:
<?php
namespace AppBundle\Entity;
use Sylius\Component\Resource\Model\ResourceInterface;
use Doctrine\ORM\Mapping as ORM;
/**
* Slider
*/
class Slider implements ResourceInterface, \Serializable
{
/**
* #var int
*/
private $id;
/**
* #var string
*/
private $lib;
/**
* #var string
*/
private $title;
/**
* #var string
*/
private $description;
private $file;
/**
* #return mixed
*/
public function getFile()
{
return $this->file;
}
/**
* #param mixed $file
*/
public function setFile($file)
{
$this->file = $file;
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set lib
*
* #param string $lib
* #return Slider
*/
public function setLib($lib)
{
$this->lib = $lib;
return $this;
}
/**
* Get lib
*
* #return string
*/
public function getLib()
{
return $this->lib;
}
/**
* Set title
*
* #param string $title
* #return Slider
*/
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 Slider
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* #return string
*/
public function getDescription()
{
return $this->description;
}
/**
* #var string
*/
private $condition;
/**
* Set condition
*
* #param string $condition
* #return Slider
*/
public function setCondition($condition)
{
$this->condition = $condition;
return $this;
}
/**
* Get condition
*
* #return string
*/
public function getCondition()
{
return $this->condition;
}
/** #see \Serializable::serialize() */
public function serialize()
{
return serialize(array(
$this->id,
$this->lib,
$this->title,
$this->description,
// see section on salt below
// $this->salt,
));
}
/** #see \Serializable::unserialize() */
public function unserialize($serialized)
{
list (
$this->id,
$this->lib,
$this->title,
$this->description,
// see section on salt below
// $this->salt
) = unserialize($serialized);
}
}
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.
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
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.