Skip to content

conditions_helper is a plugin which helps to create conditions dynamically when using ActiveRecord#find method.

Notifications You must be signed in to change notification settings

electronick/conditions_helper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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]) 

About

conditions_helper is a plugin which helps to create conditions dynamically when using ActiveRecord#find method.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages