What I tried to explain in a second time here : https://stackoverflow.com/a/19904128/875519 is that you just need first to load Movies, then Awards, and just link movies in Award fixtures, not both. Don't link Awards in movie fixtures, because when loading movie fixtures, awards will not be created, and so the script will crash...
By adding movie to an award object, this is sufficient to create the relation between both object and you'll be able call $movie->getAwards() and $award->getMovie() !
So, class Movies, remove these lines :
"awards" => [$this->getReference("award-1"), $this->getReference("award-2")
//...
foreach ($movie["awards"] as $award) {
$document->addAward($award);
}
And set order to 0 (coming before 1, have to be loaded before Awards)
public function getOrder() {
return 0; // Load before awards
}
class Awards, don't change nothing as you currently create relations with movies, make sure you load Awards after Movies by setting order to 1 :
public function load(ObjectManager $manager) {
$awards = array(
array(
"name" => "Sitges",
"year" => "1992",
"category" => "Best director"
"movie" => $this->getReference("movie-1"), // Link to a movie
array(
"name" => "Toronto''s festival",
"year" => "1992",
"category" => "FIPRESCI award",
"movie" => $this->getReference("movie-1") // Link to a movie
);
// ...
}
public function getOrder() {
return 1; // Load after movies
}
Relations between awards and movies will be saved and in the databases field movie_id (of Award class) will be completed !
So, you don't have to add relation in both fixtures. Choose one fixture class that will be loaded after the other one, and add the relation object in this chosen class, not in both, this is sufficient to create the relation between both objects and will solved your problem !