Forked from Jragon/Change.all.each { |c| c.with_rank.rank }
Last active
December 29, 2015 03:09
-
-
Save laspluviosillas/7605863 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Change < ActiveRecord::Base | |
has_many :conversations | |
validates :name, presence: true | |
def self.top_ranked(load_conversation=true) | |
with_rank(load_conversation).order("conversations_rank desc").limit(1) | |
end | |
def self.with_rank(load_conversation=true) | |
q = select("changes.*, SUM(conversations.rank) as conversations_rank").group("changes.id") | |
q = q.joins(:conversations) if load_conversation | |
return q | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Conversation < ActiveRecord::Base | |
belongs_to :discussion | |
belongs_to :change | |
validates :discussion_id, :change_id, :rank, :ten_seed, presence: true | |
validates :change_id, :rank, uniqueness: { scope: :dicussion_id } | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Discussion < ActiveRecord::Base | |
belongs_to :village | |
belongs_to :group | |
has_many :conversations | |
validates :lead_facilitator, :duration, :date_held, | |
:group_id, :village_id, presence: true | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Village < ActiveRecord::Base | |
belongs_to :programme | |
has_many :discussions | |
has_many :conversations, through: :discussions | |
has_many :changes, through: :conversations | |
validates :name, :programme_id, presence: true | |
def top_change | |
changes.merge Change.top_ranked(false) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment