Skip to content
This repository has been archived by the owner on Mar 30, 2022. It is now read-only.

Fix attribute name contains alias #120

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source :rubygems
source 'https://rubygems.org'

# Don't do a "gemspec" here. Seriously. It jacks up Jeweler.

Expand All @@ -9,4 +9,6 @@ gem "actionpack", "~> 3.1"

group :development do
gem "shoulda", "~> 2.11"
gem 'rake'
gem 'sqlite3'
end
1 change: 1 addition & 0 deletions lib/meta_search/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def matches_attribute_method(method_id)
where = Where.new(method_id) rescue nil
return nil unless method_name && where
match = method_name.match("^(.*)_(#{where.name})=?$")
return nil unless match
attribute, predicate = match.captures
attributes = attribute.split(/_or_/)
if attributes.all? {|a| where.types.include?(column_type(a))}
Expand Down
5 changes: 3 additions & 2 deletions lib/meta_search/utility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ module Utility #:nodoc:
private

def preferred_method_name(method_id)
method_name = method_id.to_s
method_name = method_id.to_s.dup # use dup otherwise sub! will change the value of method_id
where = Where.new(method_name) rescue nil
return nil unless where
where.aliases.each do |a|
break if method_name.sub!(/#{a}(=?)$/, "#{where.name}\\1")
# make sure method_name like "phone" will not convert to "phodoes_not_equal"
break if method_name.sub!(/_#{a}(=?)$/, "_#{where.name}\\1")
end
method_name
end
Expand Down