Replaces find(:first) calls.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10928 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -67,7 +67,7 @@ class AuthSourcesController < ApplicationController
|
||||
|
||||
def destroy
|
||||
@auth_source = AuthSource.find(params[:id])
|
||||
unless @auth_source.users.find(:first)
|
||||
unless @auth_source.users.exists?
|
||||
@auth_source.destroy
|
||||
flash[:notice] = l(:notice_successful_delete)
|
||||
end
|
||||
|
||||
@@ -799,7 +799,7 @@ module ApplicationHelper
|
||||
repository = project.repository
|
||||
end
|
||||
if prefix == 'commit'
|
||||
if repository && (changeset = Changeset.visible.find(:first, :conditions => ["repository_id = ? AND scmid LIKE ?", repository.id, "#{name}%"]))
|
||||
if repository && (changeset = Changeset.visible.where("repository_id = ? AND scmid LIKE ?", repository.id, "#{name}%").first)
|
||||
link = link_to h("#{project_prefix}#{repo_prefix}#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :repository_id => repository.identifier_param, :rev => changeset.identifier},
|
||||
:class => 'changeset',
|
||||
:title => truncate_single_line(h(changeset.comments), :length => 100)
|
||||
@@ -824,7 +824,7 @@ module ApplicationHelper
|
||||
:class => 'attachment'
|
||||
end
|
||||
when 'project'
|
||||
if p = Project.visible.find(:first, :conditions => ["identifier = :s OR LOWER(name) = :s", {:s => name.downcase}])
|
||||
if p = Project.visible.where("identifier = :s OR LOWER(name) = :s", :s => name.downcase).first
|
||||
link = link_to_project(p, {:only_path => only_path}, :class => 'project')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -23,7 +23,7 @@ class Document < ActiveRecord::Base
|
||||
|
||||
acts_as_searchable :columns => ['title', "#{table_name}.description"], :include => :project
|
||||
acts_as_event :title => Proc.new {|o| "#{l(:label_document)}: #{o.title}"},
|
||||
:author => Proc.new {|o| (a = o.attachments.find(:first, :order => "#{Attachment.table_name}.created_on ASC")) ? a.author : nil },
|
||||
:author => Proc.new {|o| o.attachments.reorder("#{Attachment.table_name}.created_on ASC").first.try(:author) },
|
||||
:url => Proc.new {|o| {:controller => 'documents', :action => 'show', :id => o.id}}
|
||||
acts_as_activity_provider :find_options => {:include => :project}
|
||||
|
||||
|
||||
@@ -355,7 +355,7 @@ class MailHandler < ActionMailer::Base
|
||||
}.delete_if {|k, v| v.blank? }
|
||||
|
||||
if issue.new_record? && attrs['tracker_id'].nil?
|
||||
attrs['tracker_id'] = issue.project.trackers.find(:first).try(:id)
|
||||
attrs['tracker_id'] = issue.project.trackers.first.try(:id)
|
||||
end
|
||||
|
||||
attrs
|
||||
|
||||
@@ -308,9 +308,12 @@ class Project < ActiveRecord::Base
|
||||
# Check that there is no issue of a non descendant project that is assigned
|
||||
# to one of the project or descendant versions
|
||||
v_ids = self_and_descendants.collect {|p| p.version_ids}.flatten
|
||||
if v_ids.any? && Issue.find(:first, :include => :project,
|
||||
:conditions => ["(#{Project.table_name}.lft < ? OR #{Project.table_name}.rgt > ?)" +
|
||||
" AND #{Issue.table_name}.fixed_version_id IN (?)", lft, rgt, v_ids])
|
||||
if v_ids.any? &&
|
||||
Issue.
|
||||
includes(:project).
|
||||
where("#{Project.table_name}.lft < ? OR #{Project.table_name}.rgt > ?", lft, rgt).
|
||||
where("#{Issue.table_name}.fixed_version_id IN (?)", v_ids).
|
||||
exists?
|
||||
return false
|
||||
end
|
||||
Project.transaction do
|
||||
@@ -655,7 +658,7 @@ class Project < ActiveRecord::Base
|
||||
|
||||
# Returns an auto-generated project identifier based on the last identifier used
|
||||
def self.next_identifier
|
||||
p = Project.find(:first, :order => 'created_on DESC')
|
||||
p = Project.order('created_on DESC').first
|
||||
p.nil? ? nil : p.identifier.to_s.succ
|
||||
end
|
||||
|
||||
|
||||
@@ -234,12 +234,15 @@ class Repository < ActiveRecord::Base
|
||||
def find_changeset_by_name(name)
|
||||
return nil if name.blank?
|
||||
s = name.to_s
|
||||
changesets.find(:first, :conditions => (s.match(/^\d*$/) ?
|
||||
["revision = ?", s] : ["revision LIKE ?", s + '%']))
|
||||
if s.match(/^\d*$/)
|
||||
changesets.where("revision = ?", s).first
|
||||
else
|
||||
changesets.where("revision LIKE ?", s + '%').first
|
||||
end
|
||||
end
|
||||
|
||||
def latest_changeset
|
||||
@latest_changeset ||= changesets.find(:first)
|
||||
@latest_changeset ||= changesets.first
|
||||
end
|
||||
|
||||
# Returns the latest changesets for +path+
|
||||
@@ -301,7 +304,7 @@ class Repository < ActiveRecord::Base
|
||||
return @found_committer_users[committer] if @found_committer_users.has_key?(committer)
|
||||
|
||||
user = nil
|
||||
c = changesets.find(:first, :conditions => {:committer => committer}, :include => :user)
|
||||
c = changesets.where(:committer => committer).includes(:user).first
|
||||
if c && c.user
|
||||
user = c.user
|
||||
elsif committer.strip =~ /^([^<]+)(<(.*)>)?$/
|
||||
|
||||
+1
-1
@@ -686,7 +686,7 @@ class AnonymousUser < User
|
||||
|
||||
def validate_anonymous_uniqueness
|
||||
# There should be only one AnonymousUser in the database
|
||||
errors.add :base, 'An anonymous user already exists.' if AnonymousUser.find(:first)
|
||||
errors.add :base, 'An anonymous user already exists.' if AnonymousUser.exists?
|
||||
end
|
||||
|
||||
def available_custom_fields
|
||||
|
||||
Reference in New Issue
Block a user