排序在silverstripe中有多个按一个关系

排序在silverstripe中有多个按一个关系,silverstripe,Silverstripe,在Silverstripe 3.1中,我有三个数据对象:一个问题、一个投票和一个投票人。议题有多票,;投票有一个投票人和一个议题。在我的Issue_show页面上,我想显示该问题的所有投票,按选民姓名排序 问题中的函数如下所示: public function MyVotes() { return $this->Votes(); } <% loop Votes.Sort('VoterID.Name') %> ... 但我不知道如何访问选民的名字来进行排序。

在Silverstripe 3.1中,我有三个数据对象:一个问题、一个投票和一个投票人。议题有多票,;投票有一个投票人和一个议题。在我的Issue_show页面上,我想显示该问题的所有投票,按选民姓名排序

问题中的函数如下所示:

public function MyVotes() {
     return $this->Votes();
}
<% loop Votes.Sort('VoterID.Name') %>
    ...
但我不知道如何访问选民的名字来进行排序。大概是这样吧

public function MyVotes() {
    return $this->Votes()->sort('Voter.Name');
} 

但这是一个错误。我缺少哪一步?

对于has\u-one关系,需要在字段名中添加ID后缀。此外,DataList->sort()中的关系转换不幸只能用于数组

public function MyVotes() {
return $this->Votes()->sort(array('VoterID.Name'=>'ASC'));
}

您还可以在模板中处理排序,如下所示:

public function MyVotes() {
     return $this->Votes();
}
<% loop Votes.Sort('VoterID.Name') %>
    ...

...
这还没有经过测试,但可以肯定它会起作用