Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql Rails:使用多个标准对两个不同的模型(表)进行排序_Sql_Ruby On Rails - Fatal编程技术网

Sql Rails:使用多个标准对两个不同的模型(表)进行排序

Sql Rails:使用多个标准对两个不同的模型(表)进行排序,sql,ruby-on-rails,Sql,Ruby On Rails,我有两个不同的模型(容器和库存收据),我需要合并和订购以在表中显示为交货。我目前正在对控制器中的记录进行排序: 库存收据=库存收据。其中(:交货日期.gt=>1.个月前) containers=Container.joins(:shipping).where(:shipping=>{:etd.gt=>1.month.ago}) @交货=(库存收据+集装箱)。排序!{a,b{交货日期(a) 交货日期(b)} delivery\u date是根据类返回日期的助手方法 它可以工作,但我想按供应商进行子

我有两个不同的模型(容器和库存收据),我需要合并和订购以在表中显示为交货。我目前正在对控制器中的记录进行排序:

库存收据=库存收据。其中(:交货日期.gt=>1.个月前)

containers=Container.joins(:shipping).where(:shipping=>{:etd.gt=>1.month.ago})

@交货=(库存收据+集装箱)。排序!{a,b{交货日期(a) 交货日期(b)}

delivery\u date是根据类返回日期的助手方法

它可以工作,但我想按供应商进行子排序(在SQL中:按交货日期、供应商id排序)。我可以按(交货日期)分组。按(供应商)分组,但有点难看

我想知道是否有一种更优雅的方法可以在Rails中或直接在SQL中实现这一点

谢谢各位,
Gam

您可以使用Solr和Sunspot gem等搜索引擎(http://sunspot.github.com/)它支持多模型搜索

下面是一个小例子:

search = Sunspot.search(Post,Comment) do
  with(:published_at).less_than(Time.now)
  paginate(:page => params[:page])
end

你能把你的表结构,告诉我你是如何,“从数据库中提取两个模型的记录,然后在控制器中进行”太阳黑子显然能够做到这一点,谢谢。不过,我觉得这有点过分了。