app/models/decidim/initiative.rb in decidim-initiatives-0.11.2 vs app/models/decidim/initiative.rb in decidim-initiatives-0.12.0.pre
- old
+ new
@@ -13,10 +13,11 @@
include Decidim::HasAttachments
include Decidim::HasAttachmentCollections
include Decidim::Traceable
include Decidim::Loggable
include Decidim::Initiatives::InitiativeSlug
+ include Decidim::Resourceable
belongs_to :organization,
foreign_key: "decidim_organization_id",
class_name: "Decidim::Organization"
@@ -76,25 +77,25 @@
scope :with_state, ->(state) { where(state: state) if state.present? }
scope :public_spaces, -> { published }
scope :order_by_most_recent, -> { order(created_at: :desc) }
- scope :order_by_supports, -> { order("initiative_votes_count + coalesce(offline_votes, 0) desc") }
+ scope :order_by_supports, -> { order(Arel.sql("initiative_votes_count + coalesce(offline_votes, 0) desc")) }
scope :order_by_most_commented, lambda {
select("decidim_initiatives.*")
.left_joins(:comments)
.group("decidim_initiatives.id")
- .order("count(decidim_comments_comments.id) desc")
+ .order(Arel.sql("count(decidim_comments_comments.id) desc"))
}
after_save :notify_state_change
after_create :notify_creation
def self.order_randomly(seed)
transaction do
connection.execute("SELECT setseed(#{connection.quote(seed)})")
- select('"decidim_initiatives".*, RANDOM()').order("RANDOM()").load
+ select('"decidim_initiatives".*, RANDOM()').order(Arel.sql("RANDOM()")).load
end
end
def self.log_presenter_class_for(_log)
Decidim::Initiatives::AdminLog::InitiativePresenter
@@ -221,10 +222,10 @@
attributes["hashtag"].to_s.delete("#")
end
def supports_count
face_to_face_votes = offline_votes.nil? || online? ? 0 : offline_votes
- digital_votes = offline? ? 0 : initiative_votes_count
+ digital_votes = offline? ? 0 : (initiative_votes_count + initiative_supports_count)
digital_votes + face_to_face_votes
end
# Public: Returns the percentage of required supports reached
def percentage