因为要共用一张数据表,所以几个模型共用了一些属性,所以设置了一些虚拟属性:
class Specification::Base
  ... ...
  field :a_array, :type => Array, :default => []
  ... ...
end
class Specification::Movie < Specification::Base
  ... ...
  def authors
    self.a_array
  end
  def authors=(authors)
    self.a_array = authors
  end
end
spmo = Specification::Movie.new
50000.times do |i|
  spmo.authors = ["Andy Lau#{i}", "Jackie Zhou#{i}"]
  spmo.save
  spmo.authors
end
发现 50000 次写、存、读所耗时间几乎一致,约需 27 秒,是不是可以说明虚拟属性的性能是没有问题的,与真实的属性性能相当。