【发布时间】:2010-08-04 14:34:23
【问题描述】:
我正在使用 ROR 制作一个非常简单的网站。
class Product < ActiveRecord::Base
belongs_to :category
has_many :photos
has_many :ordered_photos,
:class_name => 'Photo',
:order => 'name'
has_one :random_photo_1,
:class_name => 'Photo',
:order => 'RAND()'
def random_photo_2
Photo.find(:first, :conditions => { :product_id => self.id }, :order => 'RAND()')
end
end
在实现许多 ActiveRecord 类的过程中,我产生了疑问,我不明白 random_photo_1 实现和 random_photo_2 方法有什么不同。
附注对不起我的英语。
【问题讨论】:
标签: ruby-on-rails performance implementation