fix conversation add_message for rails 3

Change-Id: Ie07511d14005f26bc794e74e4f6a3d1f46544c47
Reviewed-on: https://gerrit.instructure.com/28343
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Cody Cutrer <cody@instructure.com>
QA-Review: James Williams  <jamesw@instructure.com>
Product-Review: James Williams  <jamesw@instructure.com>
This commit is contained in:
James Williams 2014-01-10 08:50:54 -07:00
parent b6338bb051
commit d62cc68c00
1 changed files with 10 additions and 2 deletions

View File

@ -309,7 +309,11 @@ class Conversation < ActiveRecord::Base
save! if new_tags.present? || root_account_ids_changed?
# so we can take advantage of other preloaded associations
ConversationMessage.send :add_preloaded_record_to_collection, [message], :conversation, self
if CANVAS_RAILS2
ConversationMessage.send :add_preloaded_record_to_collection, [message], :conversation, self
else
message.association(:conversation).target = self
end
message.save_without_broadcasting!
add_message_to_participants(message, options.merge(
@ -778,7 +782,11 @@ class Conversation < ActiveRecord::Base
protected
def maybe_update_timestamp(col, val, additional_conditions=[])
condition = self.class.merge_conditions(["(#{col} IS NULL OR #{col} < ?)", val], additional_conditions)
if CANVAS_RAILS2
condition = self.class.merge_conditions(["(#{col} IS NULL OR #{col} < ?)", val], additional_conditions)
else
condition = self.class.where(["(#{col} IS NULL OR #{col} < ?)", val]).where(additional_conditions).where_values.join(' AND ')
end
sanitize_sql ["#{col} = CASE WHEN #{condition} THEN ? ELSE #{col} END", val]
end
end