将两个查询合并为一个并一起分页
我有两个范围查询需要一起分页。单独而言,它们看起来像这样:
a = @person.company.tasks.open.paginate :page => params[:page], :order => (sort_column + " " + sort_direction)
b = @person.tasks.private.paginate :page => params[:page], :order => (sort_column + " " + sort_direction)
我想做类似以下的事情:
@tasks = (a + b).paginate :page => params[:page], :order => (sort_column + " " + sort_direction)
当
我执行 @tasks = (a + b)
并对结果进行分页时,我成功地进行了合并。
没有什么作用
将变量加在一起后,排序就不再起作用了。
I have two scoped queries that I need to paginate together. Individually, they look like this:
a = @person.company.tasks.open.paginate :page => params[:page], :order => (sort_column + " " + sort_direction)
b = @person.tasks.private.paginate :page => params[:page], :order => (sort_column + " " + sort_direction)
I would like to do something like the following:
@tasks = (a + b).paginate :page => params[:page], :order => (sort_column + " " + sort_direction)
What works
I do successfully get a merge when I do @tasks = (a + b)
and the results paginate.
What doesn't
With the variables added together, the sorting doesn't work any more.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以进行一个查询,根据 2 个查询返回的 id 获取任务:
这可以稍微优化一下,但这应该可以让您上路
You can make one query, getting the tasks based on the id's returned by the 2 queries:
This can be optimised a bit, but this should get you on your way