Fix query for category in default widget
This commit is contained in:
parent
5a177f34a8
commit
c27141ff5a
|
@ -23,7 +23,7 @@ class DefaultWidgetController< OrbitWidgetController
|
||||||
elsif params["category_id"].blank?
|
elsif params["category_id"].blank?
|
||||||
result = eval(@default_widget["query"])
|
result = eval(@default_widget["query"])
|
||||||
else
|
else
|
||||||
result = eval("#{ori_class_name}.where(:category_id=>params['category_id'])")
|
result = eval("#{ori_class_name}.where(get_category_field_name(ori_class_name) => params['category_id'])")
|
||||||
end
|
end
|
||||||
result.available_for_lang(I18n.locale).can_display
|
result.available_for_lang(I18n.locale).can_display
|
||||||
end
|
end
|
||||||
|
@ -47,15 +47,9 @@ class DefaultWidgetController< OrbitWidgetController
|
||||||
@data_limit = @page_part.widget_data_count.is_a?(Fixnum) ? @page_part.widget_data_count : (@page_part.widget_data_count.to_i rescue 3)
|
@data_limit = @page_part.widget_data_count.is_a?(Fixnum) ? @page_part.widget_data_count : (@page_part.widget_data_count.to_i rescue 3)
|
||||||
end
|
end
|
||||||
if @paginate
|
if @paginate
|
||||||
<<<<<<< HEAD
|
|
||||||
@data = eval(@default_widget["query"]).includes(@widget_image_field).page(params[:page_main]).per(@data_limit).desc(:created_at)
|
@data = eval(@default_widget["query"]).includes(@widget_image_field).page(params[:page_main]).per(@data_limit).desc(:created_at)
|
||||||
else
|
else
|
||||||
@data = eval(@default_widget["query"]).limit(@data_limit).includes(@widget_image_field).desc(:created_at)
|
@data = eval(@default_widget["query"]).limit(@data_limit).includes(@widget_image_field).desc(:created_at)
|
||||||
=======
|
|
||||||
@data = query_for_default_widget.includes(@widget_image_field).page(params[:page_main]).per(@data_limit)
|
|
||||||
else
|
|
||||||
@data = query_for_default_widget.limit(@data_limit).includes(@widget_image_field)
|
|
||||||
>>>>>>> 4650f80... default widget query for category and tags
|
|
||||||
end
|
end
|
||||||
case params[:type]
|
case params[:type]
|
||||||
when "typeA"
|
when "typeA"
|
||||||
|
@ -71,4 +65,11 @@ class DefaultWidgetController< OrbitWidgetController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_category_field_name(ori_class_name)
|
||||||
|
ori_class_name = ori_class_name.constantize
|
||||||
|
ori_class_name.fields.each_key do |key|
|
||||||
|
return key if key.include?('category_id')
|
||||||
|
end
|
||||||
|
nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Reference in New Issue