1

如何让我的采摘数组与 paginate 方法一起使用(我相信它只适用于 queryproxy 对象)

我的结果是拉出一些相同的节点,因为它有多个路径,所以我添加了 pluck 和 distinct 像这样..

current_user.friends....where()...params().pluck('DISTINCT e').paginate..

还有其他方法吗?还是必须在 neo4j 分页 gem 中进行更改?

4

1 回答 1

1

现在,使用该paginate方法是不可行的。WillPaginate 返回WillPaginate::Collection已经从数据库中填充的对象。我们也许可以让它返回其他东西并懒惰地评估,但我必须更多地使用它。

您可以直接创建Neo4j::Paginated对象,但这些只是从 QP 中提取的结果。

# match stupid friends with awful events, return distinct events
query = current_user.friends(:f).where(stupid: true).events(e:).rel_where(expected_attendees: 0)
@bad_events = Neo4j::Paginated.create_from(query, 1, 15).pluck('distinct e')

create_from返回一个Neo4j::Paginated委托给它的对象each并将pluck其提供给它的 QueryProxy 对象。请注意,它将根据链的末尾进行分页,因此它会根据事件执行第一页,每页 15 个。另请注意,您不能进行不同的计数。

检查https://github.com/neo4jrb/neo4j/blob/master/lib/neo4j/paginated.rb了解更多信息。这很容易阅读。

于 2015-01-13T02:16:31.933 回答