Codeigniter Datamapper 按关系排序

发布于 2024-12-04 15:05:33 字数 553 浏览 1 评论 0原文

下午好,

我正在使用 Datamapper Overzealous Edition for Codeigniter 构建一个足球联赛网站。我的所有赛程表都存储在具有以下格式的数据库表中:

ID     Competition_id    Home_team_id    Away_team_id    Etc...

正如您所猜测的,我的比赛表具有以下格式:

ID    Name

当我从数据库中获取赛程表时,我想按相关比赛名称对它们进行排序,例如,我会使用以下内容:

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

不幸的是,order_by 函数似乎不支持这种形式的语法。有人能想出一个干净的方法来完成这个任务吗?我能想到的就是手动将每个灯具放入数组中并以这种方式排序,但这似乎有很多冗余代码!

非常感谢。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅唱々樱花落 2024-12-11 15:05:33

我相信您必须加入表格并按所需字段进行排序。

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

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();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文