I have Doctrine 2 model defined as:
class Movie {
/** @Id @Column(type="integer") @GeneratedValue @var int */
private $id;
/**
* @ManyToOne(targetEntity="Language")
* @JoinColumn(nullable=false)
*/
private $default_title_language;
/**
* @OneToMany(targetEntity="MovieTitle", mappedBy="movie")
* @var MovieTitle[]
*/
protected $titles = null;
public function __construct() {
$this->titles = new ArrayCollection();
}
public function get_titles() { return $this->titles; }
public function get_title(Language $language = NULL) {
开发者_运维百科 if (is_null($language)) {
$language = $this->default_title_language;
}
// ??????????
}
public function add_title(MovieTitle $title) { $this->titles[] = $title; }
public function get_default_title_language() {
return $this->default_title_language;
}
public function set_default_title_language(Language $language) {
$this->default_title_language = $language;
}
}
so... there are Movie, MovieTitle and Language models. One Movie may have many titles (Language dependent). I want to provide Movie model with a method - which will return me only one parameterized title. How can I do this? (marked with ??????????
)
Doctrine 2.1 has indexed collections. It should do the job
http://www.doctrine-project.org/docs/orm/2.0/en/tutorials/working-with-indexed-associations.html
精彩评论