aboutsummaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/info_request_event.rb6
-rw-r--r--app/models/public_body.rb30
2 files changed, 19 insertions, 17 deletions
diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb
index 29c1ce965..263de20a0 100644
--- a/app/models/info_request_event.rb
+++ b/app/models/info_request_event.rb
@@ -327,15 +327,15 @@ class InfoRequestEvent < ActiveRecord::Base
def is_incoming_message?
- !self.incoming_message_selective_columns("incoming_messages.id").nil?
+ incoming_message_id? or (incoming_message if new_record?)
end
def is_outgoing_message?
- !self.outgoing_message.nil?
+ outgoing_message_id? or (outgoing_message if new_record?)
end
def is_comment?
- !self.comment.nil?
+ comment_id? or (comment if new_record?)
end
# Display version of status
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index fec1cefb6..5053523a3 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -160,25 +160,27 @@ class PublicBody < ActiveRecord::Base
# like find_by_url_name but also search historic url_name if none found
def self.find_by_url_name_with_historic(name)
- found = PublicBody.find(:all,
- :conditions => ["public_body_translations.url_name=?", name],
- :joins => :translations,
- :readonly => false)
- # If many bodies are found (usually because the url_name is the same across
- # locales) return any of them
- return found.first if found.size >= 1
-
- # If none found, then search the history of short names
- old = PublicBody::Version.find_all_by_url_name(name)
- # Find unique public bodies in it
- old = old.map { |x| x.public_body_id }
- old = old.uniq
+ # If many bodies are found (usually because the url_name is the same
+ # across locales) return any of them.
+ found = joins(:translations).
+ where("public_body_translations.url_name = ?", name).
+ readonly(false).
+ first
+
+ return found if found
+
+ # If none found, then search the history of short names and find unique
+ # public bodies in it
+ old = PublicBody::Version.
+ where(:url_name => name).
+ pluck('DISTINCT public_body_id')
+
# Maybe return the first one, so we show something relevant,
# rather than throwing an error?
raise "Two bodies with the same historical URL name: #{name}" if old.size > 1
return unless old.size == 1
# does acts_as_versioned provide a method that returns the current version?
- return PublicBody.find(old.first)
+ PublicBody.find(old.first)
end
# Set the first letter, which is used for faster queries