Commit 8b70b6c3 by liyijie

Add distinct_on for default for records uniq

parent 6a2ab96b
...@@ -100,6 +100,7 @@ class SimpleController::BaseController < ::InheritedResources::Base ...@@ -100,6 +100,7 @@ class SimpleController::BaseController < ::InheritedResources::Base
view_path = options.delete(:view_path) view_path = options.delete(:view_path)
@ransack_off = options.delete(:ransack_off) @ransack_off = options.delete(:ransack_off)
@paginate_off = options.delete(:paginate_off) @paginate_off = options.delete(:paginate_off)
@distinct_on = options.delete(:distinct_on)
set_view_path view_path if view_path.present? set_view_path view_path if view_path.present?
super(options) super(options)
...@@ -134,7 +135,8 @@ class SimpleController::BaseController < ::InheritedResources::Base ...@@ -134,7 +135,8 @@ class SimpleController::BaseController < ::InheritedResources::Base
end end
def ransack_paginate(association) def ransack_paginate(association)
association = association.ransack(params[:q]).result.distinct unless self.class.instance_variable_get(:@ransack_off) association = association.ransack(params[:q]).result unless self.class.instance_variable_get(:@ransack_off)
association = association.distinct unless self.class.instance_variable_get(:@distinct_on)
association = association.paginate(page: params[:page], per_page: params[:per_page]) unless self.class.instance_variable_get(:@paginate_off) association = association.paginate(page: params[:page], per_page: params[:per_page]) unless self.class.instance_variable_get(:@paginate_off)
association association
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment