【问题标题】:Ordered Many-Many Relationship in Doctrine?教义中的有序多对多关系?
【发布时间】:2011-10-09 19:55:28
【问题描述】:

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

WebsiteCategory有一个列rank,表示调用$website->getCategories()时应检索类别的顺序

我很难过,没想到这会这么难。任何人都可以帮忙吗?

【问题讨论】:

    标签: sorting symfony1 doctrine many-to-many


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      这不支持多对多关系,错误报告在下面链接了一个可能的补丁,尽管一些 cmets 表示它不起作用。正如 OP 已经指出的那样,我认为解决方案是覆盖 getCategories() 函数。

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

      【讨论】:

        【解决方案3】:

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

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

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

        【讨论】:

        • 这适用于多对一关系,但我无法获得相同类型的声明来处理多对多。考虑到我可以在 4 个地方进行排序(Local、RefClass-Local、RefClass-Foreign、Foreign),也许我只是没有正确定义它......
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-01-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多