How to write this better? Ruby Sequel chaining OR -


in sql should this:

select * `categories_description_old` ((`categories_description` = '') or (`categories_name` = '') or (`categories_heading_title` = '')) 

my (ugly) solution:

conditions = [:categories_name, :categories_heading_title, :categories_description] b = table_categories_description_old.filter(conditions.pop => "") conditions.each |m|  b = b.or(m => "") end 

is there better solution chain or conditions?

you can like:

conditions.inject(table_categories_description_old.filter(true)){|acc, cond|   acc.or(cond => '') } 

but in cases when have thought out sql query, find easier type whole condition , use sequel sanitize query parameters.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -