doctrine2 - 使用自定义查询getter

Flu*_*key 2 doctrine symfony doctrine-orm

我正在使用Symfony2和Doctrine2.我如何为get方法使用不同的查询?(措辞不好,让我解释一下)

即我有一个应用程序实体,它与Version有一对多的关系

所以在我的应用程序实体中我有:

/**
 * Get versions
 *
 * @return Doctrine\Common\Collections\Collection 
 */
public function getVersions()
{
    return $this->versions;
}
Run Code Online (Sandbox Code Playgroud)

这一切都很好,但是,我如何实现一个方法,比如

getCurrentVersion,我执行一个简单的查询,例如:

SELECT v.* FROM version WHERE application_id = 1 AND current = 1
Run Code Online (Sandbox Code Playgroud)

所以在树枝模板中,我可以这样做:

{% for application in applications %}
   Name : {{ application.name }}
   Current Version: {{ application.getCurrentVersion }}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)

任何帮助深表感谢.

ps如果我这样做错了,请赐教.

谢谢.

编辑:http://www.doctrine-project.org/docs/orm/2.1/en/reference/limitations-and-known-issues.html#join-columns-with-non-primary-keys严重?!

编辑,我真的不想这样做,这是不必要的和资源浪费:

public function getCurrentVersion
{
   foreach($this->versions as $version)
   {
      if($version->current)
      {
        return $version;
      }

   }
}
Run Code Online (Sandbox Code Playgroud)