Created
April 28, 2014 15:49
-
-
Save blex18/11376086 to your computer and use it in GitHub Desktop.
Many-to-many
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Foo\Entity; | |
use Doctrine\ORM\Mapping as ORM; | |
/** | |
* Fluid | |
* | |
* @ORM\Table(name="fluids") | |
* @ORM\Entity | |
*/ | |
class Fluid | |
{ | |
/** | |
* @var integer | |
* | |
* @ORM\Column(name="id", type="integer") | |
* @ORM\Id | |
* @ORM\GeneratedValue(strategy="AUTO") | |
*/ | |
private $id; | |
/** | |
* @ORM\Column(name="m3", type="float") | |
* @var float | |
*/ | |
protected $m3; | |
/** | |
* @ORM\ManyToMany(targetEntity="Item", inversedBy="fluids", cascade={"persist"}) | |
* @ORM\JoinTable(name="items_types", | |
* joinColumns={@ORM\JoinColumn(name="types_id", referencedColumnName="id")}, | |
* inverseJoinColumns={@ORM\JoinColumn(name="items_id", referencedColumnName="id")} | |
* ) | |
* @var Item[]|\Doctrine\Common\Collections\ArrayCollection | |
*/ | |
protected $items; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Foo\Entity; | |
use Doctrine\ORM\Mapping as ORM; | |
/** | |
* Item | |
* | |
* @ORM\Table(name="items") | |
* @ORM\Entity | |
*/ | |
class Item | |
{ | |
const TYPE_SOLID = 'solid', | |
TYPE_FLUID = 'fluid', | |
TYPE_LIQUID = 'liquid'; | |
/** | |
* @var integer | |
* | |
* @ORM\Column(name="id", type="integer") | |
* @ORM\Id | |
* @ORM\GeneratedValue(strategy="AUTO") | |
*/ | |
private $id; | |
/** | |
* @ORM\Column(name="type", type="string") | |
* @var string | |
*/ | |
protected $type; | |
/** | |
* @ORM\Column(name="name", type="string") | |
* @var string | |
*/ | |
protected $name; | |
/** | |
* @ORM\ManyToMany(targetEntity="Fluid", mappedBy="items", cascade={"persist"}) | |
* @ORM\JoinTable(name="items_types", | |
* joinColumns={@ORM\JoinColumn(name="items_id", referencedColumnName="id")}, | |
* inverseJoinColumns={@ORM\JoinColumn(name="types_id", referencedColumnName="id")} | |
* ) | |
* @var Fluid[]|\Doctrine\Common\Collections\ArrayCollection | |
*/ | |
protected $fluids; | |
/** | |
* @ORM\ManyToMany(targetEntity="Liquid", mappedBy="items", cascade={"persist"}) | |
* @ORM\JoinTable(name="items_types", | |
* joinColumns={@ORM\JoinColumn(name="items_id", referencedColumnName="id")}, | |
* inverseJoinColumns={@ORM\JoinColumn(name="types_id", referencedColumnName="id")} | |
* ) | |
* @var Liquid[]|\Doctrine\Common\Collections\ArrayCollection | |
*/ | |
protected $liquids; | |
/** | |
* @ORM\ManyToMany(targetEntity="Solid", mappedBy="items", cascade={"persist"}) | |
* @ORM\JoinTable(name="items_types", | |
* joinColumns={@ORM\JoinColumn(name="items_id", referencedColumnName="id")}, | |
* inverseJoinColumns={@ORM\JoinColumn(name="types_id", referencedColumnName="id")} | |
* ) | |
* @var Solid[]|\Doctrine\Common\Collections\ArrayCollection | |
*/ | |
protected $solids; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Foo\Entity; | |
use Doctrine\ORM\Mapping as ORM; | |
/** | |
* Liquid | |
* | |
* @ORM\Table(name="liquids") | |
* @ORM\Entity | |
*/ | |
class Liquid | |
{ | |
/** | |
* @var integer | |
* | |
* @ORM\Column(name="id", type="integer") | |
* @ORM\Id | |
* @ORM\GeneratedValue(strategy="AUTO") | |
*/ | |
private $id; | |
/** | |
* @ORM\Column(name="l", type="float") | |
* @var float | |
*/ | |
protected $l; | |
/** | |
* @ORM\ManyToMany(targetEntity="Item", inversedBy="liquids", cascade={"persist"}) | |
* @ORM\JoinTable(name="items_types", | |
* joinColumns={@ORM\JoinColumn(name="types_id", referencedColumnName="id")}, | |
* inverseJoinColumns={@ORM\JoinColumn(name="items_id", referencedColumnName="id")} | |
* ) | |
* @var Item[]|\Doctrine\Common\Collections\ArrayCollection | |
*/ | |
protected $items; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Foo\Entity; | |
use Doctrine\ORM\Mapping as ORM; | |
/** | |
* Solid | |
* | |
* @ORM\Table(name="solids") | |
* @ORM\Entity | |
*/ | |
class Solid | |
{ | |
/** | |
* @var integer | |
* | |
* @ORM\Column(name="id", type="integer") | |
* @ORM\Id | |
* @ORM\GeneratedValue(strategy="AUTO") | |
*/ | |
private $id; | |
/** | |
* @ORM\Column(name="kg", type="float") | |
* @var float | |
*/ | |
protected $kg; | |
/** | |
* @ORM\ManyToMany(targetEntity="Item", inversedBy="solids", cascade={"persist"}) | |
* @ORM\JoinTable(name="items_types", | |
* joinColumns={@ORM\JoinColumn(name="types_id", referencedColumnName="id")}, | |
* inverseJoinColumns={@ORM\JoinColumn(name="items_id", referencedColumnName="id")} | |
* ) | |
* @var Item[]|\Doctrine\Common\Collections\ArrayCollection | |
*/ | |
protected $items; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment