学说中的有序多对多关系?

发布于 2024-11-25 11:30:30 字数 257 浏览 2 评论 0原文

尝试使用 WebsiteCategory 作为 refClass 将 Categories 链接到 Websites

时应检索类别的顺序

WebsiteCategory 有一个 rank 列,它指示当您调用 $website->getCategories() 我愣住了,没想到这么难。有人可以帮忙吗?

Attempting to link Categories to Websites, using WebsiteCategory as the refClass.

WebsiteCategory has a column rank, which indicates the order in which the categories should be retrieved when you call $website->getCategories()

I'm stumped, didn't think this would be so difficult. Can anyone help?

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

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

发布评论

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

评论(3

_畞蕅 2024-12-02 11:30:30

无法获得理论来对关系进行本地排序(就像 Damien 所建议的那样),而是向模型添加了一个 getCategories() 函数,该函数运行正确的查询并返回结果集。

Was not able to get doctrine to order the relationship natively (like Damien was suggesting) instead, added a getCategories() function to the model which runs the proper query and returns the result set.

白日梦 2024-12-02 11:30:30

多对多关系不支持此功能,错误报告链接在下面,其中包含可能的补丁,尽管一些评论表明它不起作用。正如OP已经指出的,我认为解决方案是重写 getCategories() 函数。

http://www.doctrine-project.org/jira/browse/DC-651

This is not supported for Many to Many relationships, the bug report is linked below with a possible patch, although some comments indicate it was not working. As already noted by OP, I think the solution is to override the getCategories() function.

http://www.doctrine-project.org/jira/browse/DC-651

梦年海沫深 2024-12-02 11:30:30

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

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

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

You can add an orderBy param in your schema.yml:

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

You can put multi fields with a comma.

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