首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

与此同时分页查找没有关联关系的多个表

2012-09-10 
同时分页查找没有关联关系的多个表supplyinfos和seekinginfos两个表需求:实现供求信息列表,包括supplyinfo

同时分页查找没有关联关系的多个表
supplyinfos和seekinginfos两个表
需求:  实现供求信息列表,包括supplyinfos和seekinginfos两个表中的所有数据,并且按照created_at倒序排列,而且要求分页

实现:  用了5个小时的时间,终于知道怎么实现了,不多废话了,直接看实现方式,这种方式依赖于will_paginate:

Supplyinfo.paginate_by_sql("select id,name,count,user_id,created_at from supplyinfos where period=0 union all select id,name,count,user_id,created_at from seekinginfos where period = 0 order by created_at desc", :page => params[:page], :per_page => 20)

首先:  注意  unino all  可以把多个表查出来的数据关联到一起,然后paginate_by_sql可以直接使用sql语句,并且有分页功能,就这样,实现了

热点排行