Project

General

Profile

Feature #37674 » 0001-adds-missing-join-when-ordering-by-authsource-37674.patch

Jens Krämer, 2022-09-27 03:42

View differences:

app/models/user_query.rb
153 153
        #{sql_for_field(:mail, operator, value, emails, 'address')})
154 154
    SQL
155 155
  end
156

  
157
  def joins_for_order_statement(order_options)
158
    joins = [super]
159

  
160
    if order_options
161
      if order_options.include?('auth_source')
162
        joins << "LEFT OUTER JOIN #{AuthSource.table_name} auth_sources ON auth_sources.id = #{queried_table_name}.auth_source_id"
163
      end
164
    end
165

  
166
    joins.any? ? joins.join(' ') : nil
167
  end
156 168
end
test/unit/user_query_test.rb
169 169
    assert_not users.map(&:id).include? 1
170 170
  end
171 171

  
172
  def test_auth_source_ordering
173
    user = User.find(1)
174
    user.update_column :auth_source_id, 1
175

  
176
    q = UserQuery.new name: '_'
177
    q.column_names = ['id', 'auth_source.name']
178
    q.sort_criteria = 'auth_source.name'
179

  
180
    users = q.results_scope
181
    assert users.many?
182
    assert_equal user, users.last
183
  end
184

  
172 185
  def find_users_with_query(query)
173 186
    User.where(query.statement).to_a
174 187
  end
(11-11/11)