Fixed history query for model subclasses #1567

Closed
wants to merge 1 commit into
from
@@ -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
@bbenezech

bbenezech Apr 24, 2013

Collaborator

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)
@@ -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)