Module: ConsoleUtils::ActiveRecordUtils::RandomRecord::FinderMethods

Defined in:
lib/console_utils/active_record_utils/random_record.rb

Instance Method Summary collapse

Instance Method Details

#anyidObject


12
13
14
# File 'lib/console_utils/active_record_utils/random_record.rb', line 12

def anyid
  model.type_for_attribute('id').send(:cast_value, connection.select_value(select(:id).random.limit(1)))
end

#anyoneObject


8
9
10
# File 'lib/console_utils/active_record_utils/random_record.rb', line 8

def anyone
  random.first
end

#randomObject


4
5
6
# File 'lib/console_utils/active_record_utils/random_record.rb', line 4

def random
  reorder('RANDOM()')
end