-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
23 lines (15 loc) · 873 Bytes
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
conditions_helper
====================
conditions_helper is a plugin which helps to create rather complex conditions when using ActiveRecord#find method.
The main princilpe is to write conditions in form of array, array brackets will mean the same as parentheses on raw SQL condition. It's helpfull when conditions are created dynamically and you need not only AND but OR operator too.
Example:
Task.find(:all, :conditions => create_conditions([
([ "category_id = ?", category.id ] if @category),
:and,
[ ["user_id IS NULL"], :or, (["user_id = ?", @user.id] if @user)]
]))
#here condition on category_id and user_id will be added only if @category and @user are provided respectively
Install:
.script/plugin install git://github.com/electronick/conditions_helper.git
Author:
Nick Pohodnya ([email protected])