我有一个相册,里面有很多照片。 counter_cache 设置会更新相册表中的 photos_count 列。如何限制相册的照片数量?
最佳答案
就我而言,使用 validates_length_of
就足够了:
class Album
has_many :photos
validates_length_of :photos, maximum: 10
end
class Photo
belongs_to :album
validates_associated :album
end
关于ruby-on-rails - 限制 has_many 关联中的对象数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2263267/