Skip to content

Instantly share code, notes, and snippets.

@hpatoio
Last active December 13, 2015 22:29
Show Gist options
  • Select an option

  • Save hpatoio/4984907 to your computer and use it in GitHub Desktop.

Select an option

Save hpatoio/4984907 to your computer and use it in GitHub Desktop.
Player entity for OneToMany how to
<?php
namespace Acme\DemoBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Player
*
* @ORM\Table()
* @ORM\Entity
*/
class Player
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* The "many" side is ALWAYS the OWNING side in a ManyToOne bidirectional relation
* See -> http://docs.doctrine-project.org/en/latest/reference/unitofwork-associations.html#bidirectional-associations
*
* @ORM\ManyToOne(targetEntity="Team", inversedBy="players")
*
* You can read this using this "rule"
* Many {$class_name} ToOne {targetEntity} referred with {inversedBy}
*
* The inversedBy attribute contains the name of the association-field on the inverse-side.
*
*/
private $playfor;
public function __toString() {
return $this->getName();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
* @return Player
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set playfor
*
* @param \Acme\DemoBundle\Entity\Team $playfor
* @return Player
*/
public function setPlayfor(\Acme\DemoBundle\Entity\Team $playfor = null)
{
$this->playfor = $playfor;
return $this;
}
/**
* Get playfor
*
* @return \Acme\DemoBundle\Entity\Team
*/
public function getPlayfor()
{
return $this->playfor;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment