@versions = @project.shared_versions.preload(:custom_values)
@versions += @project.rolled_up_versions.visible.preload(:custom_values) if @with_subprojects
- @versions = @versions.uniq.sort
+ @versions = @versions.to_a.uniq.sort
unless params[:completed]
@completed_versions = @versions.select(&:completed?)
@versions -= @completed_versions
end
end
- scope.uniq.to_a.sort
+ scope.distinct.to_a.sort
else
[]
end
:scope => preload({:issue => :project}, :user).
joins("LEFT OUTER JOIN #{JournalDetail.table_name} ON #{JournalDetail.table_name}.journal_id = #{Journal.table_name}.id").
where("#{Journal.table_name}.journalized_type = 'Issue' AND" +
- " (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')").uniq
+ " (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')").distinct
before_create :split_private_notes
after_create :send_notification
belongs_to :user
belongs_to :principal, :foreign_key => 'user_id'
has_many :member_roles, :dependent => :destroy
- has_many :roles, lambda {uniq}, :through => :member_roles
+ has_many :roles, lambda { distinct }, :through => :member_roles
belongs_to :project
validates_presence_of :principal, :project
end
def principals
- @principals ||= Principal.active.joins(:members).where("#{Member.table_name}.project_id = ?", id).uniq
+ @principals ||= Principal.active.joins(:members).where("#{Member.table_name}.project_id = ?", id).distinct
end
def users
- @users ||= User.active.joins(:members).where("#{Member.table_name}.project_id = ?", id).uniq
+ @users ||= User.active.joins(:members).where("#{Member.table_name}.project_id = ?", id).distinct
end
# Returns the Systemwide and project specific activities
joins(projects: :enabled_modules).
where("#{Project.table_name}.status <> ?", STATUS_ARCHIVED).
where(:enabled_modules => {:name => 'issue_tracking'}).
- uniq.
+ distinct.
sorted
end
active.
joins(:members => :roles).
where(:type => types, :members => {:project_id => id}, :roles => {:assignable => true}).
- uniq.
+ distinct.
sorted
if tracker
# Returns an array of committers usernames and associated user_id
def committers
- @committers ||= Changeset.where(:repository_id => id).uniq.pluck(:committer, :user_id)
+ @committers ||= Changeset.where(:repository_id => id).distinct.pluck(:committer, :user_id)
end
# Maps committers username to a user ids
end
end
end
- joins(:projects).where(condition).uniq
+ joins(:projects).where(condition).distinct
}
def to_s; name end
if new_record?
[]
else
- @issue_status_ids ||= WorkflowTransition.where(:tracker_id => id).uniq.pluck(:old_status_id, :new_status_id).flatten.uniq
+ @issue_status_ids ||= WorkflowTransition.where(:tracker_id => id).distinct.pluck(:old_status_id, :new_status_id).flatten.uniq
end
end
scope :having_mail, lambda {|arg|
addresses = Array.wrap(arg).map {|a| a.to_s.downcase}
if addresses.any?
- joins(:email_addresses).where("LOWER(#{EmailAddress.table_name}.address) IN (?)", addresses).uniq
+ joins(:email_addresses).where("LOWER(#{EmailAddress.table_name}.address) IN (?)", addresses).distinct
else
none
end
scope.
reorder(searchable_options[:date_column] => :desc, :id => :desc).
limit(limit).
- uniq.
+ distinct.
pluck(searchable_options[:date_column], :id).
# converts timestamps to integers for faster sort
map {|timestamp, id| [timestamp.to_i, id]}
joins("LEFT JOIN #{Project.table_name} child ON #{Project.table_name}.lft <= child.lft AND #{Project.table_name}.rgt >= child.rgt").
where("child.id IN (?)", ids).
order("#{Project.table_name}.lft ASC").
- uniq.
+ distinct.
to_a
else
@projects = []
reorder(:id).lock.ids
update_all(:root_id => nil, :lft => nil, :rgt => nil)
where(:parent_id => nil).update_all(["root_id = id, lft = ?, rgt = ?", 1, 2])
- roots_with_children = joins("JOIN #{table_name} parent ON parent.id = #{table_name}.parent_id AND parent.id = parent.root_id").uniq.pluck("parent.id")
+ roots_with_children = joins("JOIN #{table_name} parent ON parent.id = #{table_name}.parent_id AND parent.id = parent.root_id").distinct.pluck("parent.id")
roots_with_children.each do |root_id|
rebuild_nodes(root_id)
end
def test_issue_with_user_custom_field
@field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true, :trackers => Tracker.all)
Role.anonymous.add_permission! :add_issues, :edit_issues
- users = Project.find(1).users.uniq.sort
+ users = Project.find(1).users.sort
tester = users.first
# Issue form
member = project.reload.memberships.detect {|m| m.principal == user}
assert_not_nil member
- assert_equal [1, 2, 3], member.roles.uniq.sort.map(&:id)
+ assert_equal [1, 2, 3], member.roles.map(&:id).uniq.sort
end
end
member = project.reload.memberships.detect {|m| m.principal == user}
assert_not_nil member
- assert_equal [1, 2, 3], member.roles.uniq.sort.map(&:id)
+ assert_equal [1, 2, 3], member.roles.map(&:id).uniq.sort
end
end
end
assert_include 'closed', p.css_classes.split
end
- def test_combination_of_visible_and_uniq_scopes_in_case_anonymous_group_has_memberships_should_not_error
+ def test_combination_of_visible_and_distinct_scopes_in_case_anonymous_group_has_memberships_should_not_error
project = Project.find(1)
member = Member.create!(:project => project, :principal => Group.anonymous, :roles => [Role.generate!])
project.members << member
assert_nothing_raised do
- Project.uniq.visible.to_a
+ Project.distinct.visible.to_a
end
end
end