Skip to content

Instantly share code, notes, and snippets.

@hpatoio
Created March 4, 2013 09:46
Show Gist options
  • Select an option

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

Select an option

Save hpatoio/5081133 to your computer and use it in GitHub Desktop.
Wrong way to add a Doctrine2 relation
<?php
namespace Acme\DemoBundle\DataFixtures\ORM;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Acme\DemoBundle\Entity\Team;
use Acme\DemoBundle\Entity\Player;
class LoadDemoDataIO implements FixtureInterface
{
public function load(ObjectManager $manager)
{
$players_source = array(
array("name" => "Diego Armando Maradona"),
array("name" => "Hristo Stoičkov"),
array("name" => "Lev Yashin")
);
$_team = new Team();
$_team->setName("Dream team A");
foreach ($players_source as $player_data) {
$_player = new Player();
$_player->setName($player_data['name']);
$_team->addPlayer($_player);
}
$manager->persist($_player);
$manager->flush();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment