Why are my Symfony/Doctrine2 entites different from my CI/D2 ones ?
(Ultimately, What is the difference between Doctrine 2 and Doctrine 2...
I know this seems like a very basic question but PLEASE before voting
down, read until the end.
This question came to my mind when using Codeigniter along with Doctrine 2.
I have noticed that, at least when using annotation, the synthax is
slightly different than when using Doctrine 2 with Symfony2 and I am
wondering why.
I'll provide an example:
This is a class in Symfony2 with a Many To One relation:
<?php
namespace Pondip\LakeBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\ORM\Mapping as ORM;
/**
* Lake
*
* @ORM\Table(name="pondip_lake")
* @ORM\Entity(repositoryClass="Pondip\LakeBundle\Entity\LakeRepository")
*/
class Lake
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var integer
* @Assert\Type(type="Pondip\LakeBundle\Entity\Venue")
*
* @ORM\ManyToOne(targetEntity="Pondip\LakeBundle\Entity\Venue")
* @ORM\JoinColumn(name="venue_id", referencedColumnName="id")
*/
private $venue;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* @var text
*
* @ORM\Column(name="description", type="text", nullable=true)
*/
private $description;
/**
* @var integer
*
* @ORM\ManyToOne(targetEntity="Pondip\UserAccountBundle\Entity\User")
* @ORM\JoinColumn(name="created_by", referencedColumnName="id",
nullable=true)
*/
private $createdBy;
please pay attention to all the @ORM\ everywhere.
Now, when using this with codeigniter2/Doctrine2.3.0 I have Mapping errors
in my console. But, when following some tuts, I ended up removing all of
the ORM\ (and the corresponding use Doctrine\ORM\Mapping as ORM) and it
worked.
This work :
<?php
namespace Entity;
/**
* Friend Model
*
* @Entity
* @Table(name="friend")
* @author Miles Yohann Merran <hello_miles@hotmail.com>
*/
class Friend
{
/**
* @Id
* @Column(type="integer", nullable=false)
* @GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @Column(type="string", length=32, unique=true, nullable=false)
*/
protected $name;
/**
* @Column(type="text", nullable=false)
*/
protected $description;
/**
* @Column(type="string", length=64, nullable=false)
*/
protected $picture;
/**
* @Column(type="string", length=64, nullable=false)
*/
protected $genre;
/**
* @ManyToOne(targetEntity="User", inversedBy="friends")
* @JoinColumn(nullable=false)
*/
protected $user;
/**
* @var datetime $date
*
* @Column(name="date", type="datetime")
*/
protected $date;
When this doesn't work (pay attention at the ORM)
<?php
namespace Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Friend Model
*
* @Entity
* @Table(name="friend")
* @author Miles Yohann Merran <hello_miles@hotmail.com>
*/
class Friend
{
/**
* @Id
* @Column(type="integer", nullable=false)
* @GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @Column(type="string", length=32, unique=true, nullable=false)
*/
protected $name;
/**
* @Column(type="text", nullable=false)
*/
protected $description;
/**
* @Column(type="string", length=64, nullable=false)
*/
protected $picture;
/**
* @Column(type="string", length=64, nullable=false)
*/
protected $genre;
/**
* @ORM\ManyToOne(targetEntity="User", inversedBy="friends")
* @ORM\JoinColumn(nullable=false)
*/
protected $user;
/**
* @var datetime $date
*
* @ORM\Column(name="date", type="datetime")
*/
protected $date;
Why ? What is the difference ?
No comments:
Post a Comment