フィクスチャを作成していますが、それらをロードしようとするとエラーが発生します。私は Movie オブジェクトのインスタンスを必要としていますが、私が与えるものは、理由はわかりませんが、整数です。このため、次のエラーがあると表示されます。
[Symfony\Component\Debug\Exception\ContextErrorException]
Catchable Fatal Error: Argument 1 passed to Filmboot\MovieBundle\Document\A
ward::setMovie() must be an instance of Filmboot\MovieBundle\Document\Movie
, integer given, called in C:\Programming\xampp\htdocs\filmboot.web\src\Fil
mboot\MovieBundle\DataFixtures\MongoDB\Awards.php on line 143 and defined i
n C:\Programming\xampp\htdocs\filmboot.web\src\Filmboot\MovieBundle\Documen
t\Award.php line 107
これは私の Fixture クラスです:
namespace Filmboot\MovieBundle\DataFixtures\MongoDB;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Filmboot\MovieBundle\Document\Award;
class Awards extends AbstractFixture implements OrderedFixtureInterface {
public function load(ObjectManager $manager) {
$awards = array(
array(
"name" => "Sitges",
"year" => "1992",
"category" => "Best director"
);
foreach ($awards as $award) {
$document = new Award();
$document->setName ($award["name"]);
$document->setYear ($award["year"]);
$document->setCategory($award["category"]);
$manager->persist($document);
$this->addReference("award-" .$i, $award);
}
$manager->flush();
}
public function getOrder() {
return 1;
}
}
そして、これはドキュメントクラスです:
namespace Filmboot\MovieBundle\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use Doctrine\Common\Collections\ArrayCollection;
use Filmboot\MovieBundle\Util;
/**
* @ODM\Document(db="filmbootdb", collection="awards")
* @ODM\Document(repositoryClass="Filmboot\MovieBundle\Document\AwardRepository")
*/
class Award {
/**
* @ODM\Id
*/
private $id;
/**
* @ODM\String
*/
private $name;
/**
* @ODM\Int
*/
private $year;
/**
* @ODM\String
*/
private $category;
/**
* @ODM\ReferenceOne(targetDocument="Movie", mappedBy="awards", cascade={"persist"})
*/
private $movie;
public function getId() {
return $this->id;
}
public function setName($name) {
return $this->name = $name;
}
public function getName() {
return $this->name;
}
public function setYear($year) {
return $this->year = $year;
}
public function getYear() {
return $this->year;
}
public function setCategory($category) {
return $this->category = $category;
}
public function getCategory() {
return $this->category;
}
public function setMovie(\Filmboot\MovieBundle\Document\Movie $movie) {
$movie->setAward($this);
return $this->movie = $movie;
}
}