app/controllers/apicasso/crud_controller.rb in apicasso-0.2.10 vs app/controllers/apicasso/crud_controller.rb in apicasso-0.2.11
- old
+ new
@@ -172,16 +172,14 @@
# Parsed JSON to be used as response payload, with included relations
def include_relations
@records = JSON.parse(included_collection.to_json(include: parsed_include))
end
- # A way to SQL-include if available for current param[:include]
+ # A way to SQL-include for current param[:include], only if available
def included_collection
- if @records.try(:includes, parsed_include).present?
- @records.includes(parsed_include)
- else
- @records
- end
+ @records.includes(parsed_include)
+ rescue ActiveRecord::AssociationNotFoundError
+ @records
end
# Returns the collection checking if it needs pagination
def collection_response
if params[:per_page].to_i < 0