ruby on rails - Different implementation on ROR -
I am creating a very simple website with ROR.
class product & lt; ActiveRecord :: Base is_to: Category has_many: photos has_many: order_photos ,: class_name = & gt; 'Photo' ,: Order = & gt; 'Name' has_one: random_photo_1 ,: class_name = & gt; 'Photo' ,: Order = & gt; 'Rand ()' DF Random_photo_2 photo.fund (: first, conditions = & gt; {product_id = & gt; shelf id} ,: order = & gt; 'rand ()') and end
While implementing several sections of ActiveCardord, I suspect, I do not remember that this is a different random_photo_2 method between random_photo_1 implementation.
PS I apologize for my english.
They both will do the same thing. / P>
Its Benefits: random_photo_1 is that whenever you search for many products, you can easily load all the "Random Photos" Association, which will really help to improve performance if You are going to show many products and a random picture of them on your scene.
#: Organizations @ products from eagerness. Product load. (Load all:: = => random_photo_1)
Then, Whenever you go to @products
on your scene, if you do:
@ products.each do | Products | # It will not make any new choices against the database & lt;% = product.random_photo_1% & gt; End
Comments
Post a Comment