Use dot notation for attr_name and valid?, type_for adjustments

If `skills_name_cont` is passed in where skills is a embeds_many relation and name is the attribute of the Skill, the attr_name will becomes `skills.name` which will be passed in to the resulting predication query.
This commit is contained in:
Penn Su 2015-01-21 01:27:31 -08:00
parent f55770f4d7
commit ab8bda9af8
2 changed files with 5 additions and 5 deletions

View File

@ -21,7 +21,7 @@ module Ransack
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
@ -38,7 +38,7 @@ module Ransack
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
@ -114,10 +114,10 @@ module Ransack
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

View File

@ -21,7 +21,7 @@ module Ransack
def valid?
bound? && attr &&
context.klassify(parent).ransackable_attributes(context.auth_object)
.include?(attr_name)
.include?(attr_name.split('.').last)
end
def type