Skip to content

Instantly share code, notes, and snippets.

@e-vural
Created January 3, 2018 08:45
Show Gist options
  • Save e-vural/1c791fb13d360cd38047740925ccea6f to your computer and use it in GitHub Desktop.
Save e-vural/1c791fb13d360cd38047740925ccea6f to your computer and use it in GitHub Desktop.
### Profile entity
class Profile{
... (your entity codes)
//ONE TO MANY RELATİONSHİP
/**
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Graduate",mappedBy="profile",cascade={"all"})
*/
private $graduates;
//THİS CODE NOT GENARATE AUTO FROM SYMFONY (php bin/consele do:ge:entity App
/**
* Get graduates
*
* @return \Doctrine\Common\Collections\Collection
*/
public function setGraduates(\AppBundle\Entity\Graduate $graduate)
{
$this->graduates[] = $graduate;
$graduate->setProfile($this);//This is important code
return $this;
}
}
####Graduate entity
class Graduate{
... (your entity codes)
//MANY TO ONE RELATİONSHİP
/**
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Profile", inversedBy="graduates")
* @ORM\JoinColumn(name="profile_id",referencedColumnName="id",onDelete="CASCADE")
*/
private $profile;
}
##FORMBUİLDER PROFİLE
class ProfileType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
... (your form codes)
$builder->add('graduates', GraduateType::class, array("label" => false));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment