Skip to content

Commit

Permalink
Merge pull request prograils#16 from Bonias/use-arel-to-create-search…
Browse files Browse the repository at this point in the history
…-sql

Use arel to create search conditions.
  • Loading branch information
mlitwiniuk committed Oct 16, 2013
2 parents d855d06 + a8e2d53 commit ea4102c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/models/lit/localization_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,21 @@ def self.search(options={})
else
s = s.ordered
end
localization_key_col = Lit::LocalizationKey.arel_table[:localization_key]
default_value_col = Lit::Localization.arel_table[:default_value]
translated_value_col = Lit::Localization.arel_table[:translated_value]
if options[:key_prefix].present?
q = "#{options[:key_prefix]}%"
s = s.where('lit_localization_keys.localization_key like ?', q)
s = s.where(localization_key_col.matches(q))
end
if options[:key].present?
q = "%#{options[:key]}%"
s = s.joins([:localizations]).where('lit_localization_keys.localization_key like ? or lit_localizations.default_value like ? or lit_localizations.translated_value like ?', q, q, q)
cond = localization_key_col.matches(q).or(
default_value_col.matches(q).or(
translated_value_col.matches(q)
)
)
s = s.joins([:localizations]).where(cond)
end
if not options[:include_completed].to_i==1
s = s.not_completed
Expand Down

0 comments on commit ea4102c

Please sign in to comment.