开发者

Codeigniter Datamapper order by relation

Good afternoon,

I am using Datamapper Overzealous Edition for Codeigniter to build a football league website. All of my fixtures are stored within a database table with the following format:

ID     Competition_id    Home_team_id    Away_team_id    Etc...

As you guessed, 开发者_开发百科my competitions table has the following format:

ID    Name

When I get my fixtures from the database, I would like to order them by the related competitions name so for example, I would use the following:

$fixtures = new fixtures();
$fixtures->order_by('competition/name','asc')->get();

Unfortunately, it seems that the order_by function does not support this form of syntax. Can anybody come up with a clean way to accomplish this? All I can think of is manually placing every fixture into an array and ordering that way but that would seem like alot of redundant code!

Many thanks in advance.

Dan


I believe you have to join the table and sort on the field needed.

$fixtures = new fixtures();
$fixtures->include_related('competition', 'name', true)->order_by('competition_name', 'ASC')->get();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜