Modify SQL in RecentView factory to support MySQL
This commit is contained in:
parent
d51d22213f
commit
3c1e8ba123
1 changed files with 8 additions and 1 deletions
|
@ -9,7 +9,14 @@ FactoryBot.define do
|
||||||
|
|
||||||
# select a random record of the given object class
|
# select a random record of the given object class
|
||||||
o_id do
|
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
|
end
|
||||||
|
|
||||||
# assign to an existing user, if possible
|
# assign to an existing user, if possible
|
||||||
|
|
Loading…
Reference in a new issue