summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeiko Bernloehr <Heiko.Bernloehr@FreeIT.de>2017-03-08 12:52:34 +0100
committerHeiko Bernloehr <Heiko.Bernloehr@FreeIT.de>2017-03-08 12:52:34 +0100
commit928ec633459c157d4f6c575f0adfc22d74bda167 (patch)
treed1b3bc1906a7ba8ec888e5bcc551664599685cbc
parente3bbd2be30d2cc16edf8a61df78b0dd953d0761a (diff)
downloadecs-928ec633459c157d4f6c575f0adfc22d74bda167.tar.gz
ecs-928ec633459c157d4f6c575f0adfc22d74bda167.zip
Change Event scopes to Arel syntax.
-rw-r--r--app/models/event.rb20
1 files changed, 12 insertions, 8 deletions
diff --git a/app/models/event.rb b/app/models/event.rb
index 25c8cf2..126048d 100644
--- a/app/models/event.rb
+++ b/app/models/event.rb
@@ -28,14 +28,18 @@ class Event < ActiveRecord::Base
private
# if count <0 then list all events otherwise maximal count events
- scope :for_participant, lambda { |participant_id,count| {
- :conditions => { :participant_id => participant_id },
- -> { order 'id ASC' },
- count<0 ? :readonly : :limit => count }}
- scope :for_participant_and_message_desc_order, lambda { |participant_id,message_id| {
- :conditions => { :participant_id => participant_id, :message_id => message_id },
- -> { order 'id DESC' },
- :limit => 1 }}
+ scope :for_participant, lambda { |participant_id,count|
+ if(count<0)
+ where(:participant_id => participant_id).
+ order('id ASC')
+ else
+ where(:participant_id => participant_id).
+ order('id ASC').limit(count)
+ end
+ }
+ scope :for_participant_and_message_desc_order, lambda { |participant_id,message_id|
+ where(:participant_id => participant_id, :message_id => message_id).
+ order('id DESC').limit(1) }
def self.make(options)
options.assert_valid_keys(:event_type_name, :membership_message, :participant, :message)