手机站
网通分站
电信主站
密 码:
用户名:
当前位置 : 主页>程序设计>Java技术>列表

插件rquerypad, 简化查询参数 增强关联查询能力

来源: 作者: 时间:2008-04-02
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!
Simplify query options with association automation and improve inner join for activerecord of rails
字段名包含关联信息,不需额外再写include或者joins
原来activerecord仅支持inner join在最后,现在没有这个限制

不想用svn,直接下载可以到 https://rubyforge.org/projects/rquerypad/

Feature
=======
1. single name string decribe associations
2. support to mix inner join and outer join with any order
3. auto remove duplicated joins from other association in different depth
4. support :conditions, :order, :group
5. auto merge to original :include, :joins

Install
=======
ruby script/plugin install http://rquerypad.googlecode.com/svn/trunk/rquerypad

Example
=======
suppose the asscociations of User <-> Thread <-> Reply is 1:N:N

Ruby代码 复制代码
  1. @users = User.find(:all:group => ["threads.created_at""name"])   
  2. generate:   
  3. [:all, {:group=>"threads.created_at, users.name":include=>[:threads]}]   
  4.   
  5. @users = User.find(:all:conditions => ["threads_.replies.title = ?",   
  6. "rquerypad"])   
  7. generate:   
  8. [:all, {:inner_joins=>["threads"], :conditions=>["replies.title = ?""rquerypad"], :include=>[{:threads=>:replies}]}]   
  9. #note: the :inner_joints is processed by rquerypad before sending sql to database   
  10.   
  11. @users = User.find(:all:conditions => ["threads.replies.title = ? and threads.id = ?""rquerypad", 1])   
  12. generate:   
  13. [:all, {:conditions=>["replies.title = ? and threads.id = ?""rquerypad", 1], :include=>[{:threads=>:replies}]}]   
  14. #note: single "threads" was removed from includes  


Setup
=======
#to set debug model, in rails initialized script
$RQUERYPAD_DEBUG = true

#to support rails 1.2.6, in rails initialized script, such as environment.rb
#default support rails 2.0
$RQUERYPAD_RAILS = "1.2"


Test
=======
Note: current migrate script works only in rails 2.0

1.Prepare

the test depends on sqlite3 database, the following code should be add into your database.yml and place rquerypad.rb(copy from test.rb) in config/environment

rquerypad:
adapter: sqlite3
database: vendor/plugins/rquerypad/test/db.rquerypad
timeout: 5000

2.database migrate

execute the following script

rake migrate

3.start test

execute the following script
rake

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!