Revision ed7e5184
Added by Amit Karsale over 7 years ago
app/controllers/api/base_controller.rb | ||
---|---|---|
association = resource_class.reflect_on_all_associations.find {|assoc| assoc.plural_name == parent_name.pluralize}
|
||
#if couldn't find an association by name, try to find one by class
|
||
association ||= resource_class.reflect_on_all_associations.find {|assoc| assoc.class_name == parent_name.camelize}
|
||
result_scope = resource_class.joins(association.name).merge(scope)
|
||
result_scope = resource_class_join(association, scope)
|
||
# Check that the scope resolves before return
|
||
result_scope if result_scope.to_a
|
||
rescue ActiveRecord::ConfigurationError
|
||
... | ... | |
where(association.name => scope.map(&:id))
|
||
end
|
||
|
||
def resource_class_join(association, scope)
|
||
resource_class.joins(association.name).merge(scope)
|
||
end
|
||
|
||
def resource_scope_for_index(options = {})
|
||
resource_scope(options).search_for(*search_options).paginate(paginate_options)
|
||
end
|
Also available in: Unified diff
Fixes #13775 - merge if data set is present
(cherry picked from commit 8e81effcedafc539cbe3477b5565d9239f1f2f51)