When creating a (factory_girl) factory for an object that has an optional has_many relation, I would like for the factory to create a variable number of objects on the relation. I have the following code, which works, but I suspect there is a better way of doing this:

Factory.define(:product) do |p|
  p.name {Faker::Lorem.words(3)}

  p.images do
    instances = []
    rand(10).times {instances << Factory.build(:image)}
    instances
  end

end

Anyone have any thoughts?