Modify SQL in RecentView factory to support MySQL

This commit is contained in:
Ryan Lue 2018-09-11 14:46:10 +08:00 committed by Ryan Lue
parent d51d22213f
commit 3c1e8ba123

View file

@ -9,7 +9,14 @@ FactoryBot.define do
# select a random record of the given object class
o_id do
type.to_s.camelcase.constantize.order('RANDOM()').first.id
random_function = case ActiveRecord::Base.connection_config[:adapter]
when 'mysql2'
'RAND'
when 'postgresql'
'RANDOM'
end
type.to_s.camelcase.constantize.order("#{random_function}()").first.id
end
# assign to an existing user, if possible