我有一个带有movies
and的数据库awards
。关键是我想要的是能够知道一个奖项的电影和一个电影的奖项。当我尝试加载电影或奖项时,问题就开始了。当我加载其中一个时,我有一个错误,例如:undefined award-1
或反之亦然(undefined movie-1
),因为尚未创建引用。
我的颁奖典礼:
namespace MyProject\MovieBundle\DataFixtures\MongoDB;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use MyProject\MovieBundle\Document\Award;
class Awards extends AbstractFixture implements OrderedFixtureInterface {
public function load(ObjectManager $manager) {
$awards = array(
array(
"name" => "Sitges",
"year" => "1992",
"category" => "Best director"
"movie" => $this->getReference("movie-1"),
array(
"name" => "Toronto''s festival",
"year" => "1992",
"category" => "FIPRESCI award",
"movie" => $this->getReference("movie-1")
);
foreach ($awards as $i => $award) {
$i++;
$document = new Award();
$document->setName ($award["name"]);
$document->setYear ($award["year"]);
$document->setCategory($award["category"]);
$manager->persist($document);
$this->addReference("award-" . $i, $document);
}
$manager->flush();
}
public function getOrder() {
return 1;
}
}
和电影夹具:
namespace Filmboot\MovieBundle\DataFixtures\MongoDB;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Filmboot\MovieBundle\Document\Movie;
class Movies extends AbstractFixture implements OrderedFixtureInterface {
public function load(ObjectManager $manager) {
$movies = array(
array(
"title" => "Reservoir Dogs",
"duration" => "95",
"year" => "1992",
"country" => "USA",
"producer" => "Live Entertainment, Dog Eat Dog Productions Inc.",
"image" => "reservoirdogs.png",
"largeImage" => "reservoirdogsLarge.png",
"awards" => [$this->getReference("award-1"), $this->getReference("award-2")
);
foreach ($movies as $i => $movie) {
$i++;
$document = new Movie();
$document->setTitle ($movie["title"]);
$document->setDuration ($movie["duration"]);
$document->setyear ($movie["year"]);
$document->setProducer ($movie["producer"]);
$document->setImage ($movie["image"]);
$document->setLargeImage($movie["largeImage"]);
foreach ($movie["awards"] as $award) {
$document->addAward($award);
}
$manager->persist($document);
$manager->flush();
$this->addReference("movie-".$i, $document);
}
}
public function getOrder() {
return 1;
}
}