我将Doctrine 2模型定义为:
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;
}
}
所以...有电影,MovieTitle和语言模型。一部电影可能有许多标题(取决于语言)。我想为一个方法提供Movie模型 - 这将只返回一个参数化标题。我怎样才能做到这一点? (标有??????????
)
答案 0 :(得分:1)
Doctrine 2.1已将索引编入索引。它应该做的工作
http://www.doctrine-project.org/docs/orm/2.0/en/tutorials/working-with-indexed-associations.html