lib/ransack/adapters/mongoid/context.rb in ransack-1.6.6 vs lib/ransack/adapters/mongoid/context.rb in ransack-1.7.0

- old
+ new

@@ -19,11 +19,11 @@ object.all end def type_for(attr) return nil unless attr && attr.valid? - name = attr.arel_attribute.name.to_s + name = attr.arel_attribute.name.to_s.split('.').last # table = attr.arel_attribute.relation.table_name # schema_cache = @engine.connection.schema_cache # raise "No table named #{table} exists" unless schema_cache.table_exists?(table) # schema_cache.columns_hash(table)[name].type @@ -36,11 +36,11 @@ # when :decimal # else # :string name = '_id' if name == 'id' - t = object.klass.fields[name].type + t = object.klass.fields[name].try(:type) || @bind_pairs[attr.name].first.fields[name].type t.to_s.demodulize.underscore.to_sym end def evaluate(search, opts = {}) @@ -112,13 +112,13 @@ found_assoc = nil while remainder.unshift( segments.pop) && segments.size > 0 && !found_assoc do assoc, klass = unpolymorphize_association(segments.join('_')) if found_assoc = get_association(assoc, parent) - join = build_or_find_association(found_assoc.name, parent, klass) parent, attr_name = get_parent_and_attribute_name( - remainder.join('_'), join + remainder.join('_'), found_assoc.klass ) + attr_name = "#{segments.join('_')}.#{attr_name}" end end end [parent, attr_name]