Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed history query for model subclasses #1567

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/rails_admin/extensions/paper_trail/auditing_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ def listing_for_model(model, query, sort, sort_reverse, all, page, per_page = (R
sort = :created_at
sort_reverse = "true"
end
versions = ::Version.where :item_type => model.model.name
if model.model.base_class.name == model.model.name
versions = ::Version.where :item_type => model.model.name
else
versions = ::Version.where :item_id => model.model.all
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure? This line looks really awkward to me!

end
versions = versions.where("event LIKE ?", "%#{query}%") if query.present?
versions = versions.order(sort_reverse == "true" ? "#{sort} DESC" : sort)
versions = all ? versions : versions.send(Kaminari.config.page_method_name, page.presence || "1").per(per_page)
Expand All @@ -81,7 +85,7 @@ def listing_for_object(model, object, query, sort, sort_reverse, all, page, per_
sort = :created_at
sort_reverse = "true"
end
versions = ::Version.where :item_type => model.model.name, :item_id => object.id
versions = ::Version.where :item_type => model.model.base_class.name, :item_id => object.id
versions = versions.where("event LIKE ?", "%#{query}%") if query.present?
versions = versions.order(sort_reverse == "true" ? "#{sort} DESC" : sort)
versions = all ? versions : versions.send(Kaminari.config.page_method_name, page.presence || "1").per(per_page)
Expand Down