【问题标题】:Sort over ManyToOne Relationship with KnpPaginatorBundle in Symfony2在 Symfony2 中使用 KnpPaginatorBundle 对多对一关系进行排序
【发布时间】:2012-04-25 15:36:18
【问题描述】:

我在 Symfony2 项目中使用 KnpPaginatorBundle。我得到了 2 个具有 manyToOne 关系的实体。

/**
 * @ORM\Entity
 * @ORM\Table(name="foo")
 */
class foo {
   ...

   /**
     * @ORM\ManyToOne(targetEntity="abc\DemoBundle\Entity\Bar")
     * @ORM\JoinColumn(name="bar_id", referencedColumnName="id")
     */
    protected $bar;

    ...
}

/**
 * @ORM\Entity
 * @ORM\Table(name="bar")
 */
class Bar {
   ...

    /**
     * @ORM\Column(type="string", length=50, nullable=true)
     */
    protected $name;

    ...
}

现在我想用 KnpPaginatorBundle 进行排序

<{{  entities.sortable('bar', 'i.bar')|raw }}

我收到以下错误消息

There is no such field [bar] in the given Query component, aliased by [i]

有什么方法可以使用 bar.name 使 foo 中的 bar 可排序?

干杯

【问题讨论】:

    标签: symfony doctrine-orm bundle jquery-ui-sortable many-to-one


    【解决方案1】:

    您必须在向 KnpPaginatorBundle 提供的查询中加入表

    SELECT i
    FROM abc\DemoBundle\Entity\Bar i
    JOIN i.bar b 
    

    现在您可以使用以下内容进行排序:

    <{{  entities.sortable('bar', 'b.name')|raw }}>
    

    【讨论】:

      【解决方案2】:

      我相信 sortable 需要一个标签和一个列。所以你可能正在寻找

      <{{ entities.sortable('Name', 'i.name')|raw }}
      

      【讨论】:

        猜你喜欢
        • 2012-02-20
        • 1970-01-01
        • 2013-03-05
        • 2013-07-21
        • 2015-03-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-03-08
        相关资源
        最近更新 更多