插件rquerypad, 简化查询参数 增强关联查询能力
2008-04-02 02:30:18来源: 阅读 ()
字段名包含关联信息,不需额外再写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
- @users = User.find(:all, :group => ["threads.created_at", "name"])
- generate:
- [:all, {:group=>"threads.created_at, users.name", :include=>[:threads]}]
- @users = User.find(:all, :conditions => ["threads_.replies.title = ?",
- "rquerypad"])
- generate:
- [:all, {:inner_joins=>["threads"], :conditions=>["replies.title = ?", "rquerypad"], :include=>[{:threads=>:replies}]}]
- #note: the :inner_joints is processed by rquerypad before sending sql to database
- @users = User.find(:all, :conditions => ["threads.replies.title = ? and threads.id = ?", "rquerypad", 1])
- generate:
- [:all, {:conditions=>["replies.title = ? and threads.id = ?", "rquerypad", 1], :include=>[{:threads=>:replies}]}]
- #note: single "threads" was removed from includes
@users = User.find(:all, :group => ["threads.created_at", "name"]) generate: [:all, {:group=>"threads.created_at, users.name", :include=>[:threads]}] @users = User.find(:all, :conditions => ["threads_.replies.title = ?", "rquerypad"]) generate: [:all, {:inner_joins=>["threads"], :conditions=>["replies.title = ?", "rquerypad"], :include=>[{:threads=>:replies}]}] #note: the :inner_joints is processed by rquerypad before sending sql to database @users = User.find(:all, :conditions => ["threads.replies.title = ? and threads.id = ?", "rquerypad", 1]) generate: [:all, {:conditions=>["replies.title = ? and threads.id = ?", "rquerypad", 1], :include=>[{:threads=>:replies}]}] #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
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash