Bekijk de OneToMany bidirectionele opstelling
Hier is een voorbeeld met annotaties:
/**
* @Entity
* @Table( name="country" )
*/
class Country
{
/**
* @Id
* @Column(type="integer")
* @GeneratedValue
*/
public $id;
/**
* @Column( type="string", length=30, name="name", nullable=false )
*/
public $name;
/**
* @OneToMany( targetEntity="City", mappedBy="Country" )
*/
private $cities;
}
/**
* @Entity
* @Table( name="city" )
*/
class City
{
/**
* @Id
* @Column(type="integer")
* @GeneratedValue
*/
public $id;
/**
* @ManyToOne( targetEntity="Country" )
* @JoinColumn( name="country", referencedColumnName="id" )
*/
public $country;
/**
* @Column( type="string", length=30, name="name", nullable=false )
*/
public $name;
}
U moet dit instellen om de $country->getCities()
. toe te staan methode om te werken