Rquerypad
Simplify query options with association automation and improve inner join for activerecord of rails
Feature
-
single name string decribe associations
-
support to mix inner join and outer join with any order
-
auto remove duplicated joins from other association in different depth
-
support :conditions, :order, :group
-
auto merge to original :include, :joins
Install
ruby script/plugin install rquerypad.rubyforge.org/svn/trunk/rquerypad or ruby script/plugin install 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, users.name”, :include=>
-
@users = User.find(:all, :conditions => [“threads_.replies.title = ?”, “rquerypad”]) generate:
- :all, href=""threads"">inner_joins=>, :conditions=>[“replies.title = ?”, “rquerypad”], :include=>}
-
#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, = ? and threads.id = ?”, “rquerypad”, 1], :include=>}
-
#note: single “threads” was removed from includes
Setup
#to set debug model, in rails initialized script $RQUERYPAD_DEBUG = true
Test
Note: current migrate script works only in rails 2.0 or later
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: 50002.database migrate
execute the following script
rake migrate
3.start test
execute the following script rake
Copyright © 2008 Leon Li, released under the MIT license