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:
parent
f55770f4d7
commit
ab8bda9af8
|
@ -21,7 +21,7 @@ module Ransack
|
||||||
|
|
||||||
def type_for(attr)
|
def type_for(attr)
|
||||||
return nil unless attr && attr.valid?
|
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
|
# table = attr.arel_attribute.relation.table_name
|
||||||
|
|
||||||
# schema_cache = @engine.connection.schema_cache
|
# schema_cache = @engine.connection.schema_cache
|
||||||
|
@ -38,7 +38,7 @@ module Ransack
|
||||||
|
|
||||||
name = '_id' if name == 'id'
|
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
|
t.to_s.demodulize.underscore.to_sym
|
||||||
end
|
end
|
||||||
|
@ -114,10 +114,10 @@ module Ransack
|
||||||
segments.pop) && segments.size > 0 && !found_assoc do
|
segments.pop) && segments.size > 0 && !found_assoc do
|
||||||
assoc, klass = unpolymorphize_association(segments.join('_'))
|
assoc, klass = unpolymorphize_association(segments.join('_'))
|
||||||
if found_assoc = get_association(assoc, parent)
|
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(
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -21,7 +21,7 @@ module Ransack
|
||||||
def valid?
|
def valid?
|
||||||
bound? && attr &&
|
bound? && attr &&
|
||||||
context.klassify(parent).ransackable_attributes(context.auth_object)
|
context.klassify(parent).ransackable_attributes(context.auth_object)
|
||||||
.include?(attr_name)
|
.include?(attr_name.split('.').last)
|
||||||
end
|
end
|
||||||
|
|
||||||
def type
|
def type
|
||||||
|
|
Loading…
Reference in New Issue