Sorting 条令中有多少关系?

Sorting 条令中有多少关系?,sorting,symfony1,doctrine,many-to-many,Sorting,Symfony1,Doctrine,Many To Many,试图将类别链接到网站,使用网站类别作为refClass websitecegory有一列rank,指示调用$website->getCategories()时检索类别的顺序。 我被难住了,没想到这会这么难。有人能帮忙吗 您可以在schema.yml中添加orderBy参数: Gallery: columns: title: string(255) relations: Images: local: id foreign: gallery_id

试图将
类别
链接到
网站
,使用
网站类别
作为refClass

websitecegory
有一列
rank
,指示调用
$website->getCategories()时检索类别的顺序。


我被难住了,没想到这会这么难。有人能帮忙吗

您可以在schema.yml中添加orderBy参数:

Gallery:
  columns:
    title: string(255)
  relations:
    Images:
      local: id
      foreign: gallery_id
      foreignAlias: Gallery
      type: many
      orderBy: position DESC

您可以使用逗号放置多个字段。

无法让条令以本机方式对关系进行排序(如Damien所建议的),而是向模型添加了一个getCategories()函数,该函数将运行正确的查询并返回结果集

这在多对多关系中不受支持,错误报告在下面链接了一个可能的补丁,尽管一些评论指出它不起作用。正如OP所指出的,我认为解决方案是重写getCategories()函数


这适用于多个“一”关系,但我无法使同一类型的声明适用于多个“多”关系。考虑到有4个地方我可以进行排序(本地,RefClass本地,RefClass外来,外来),也许我只是没有正确定义它。。。