Rails sql延迟加载和自带缓存
color_lot_manuallies = color_lot.color_lot_manualliesif color_lot_manuallies.size == 1end
ArticleMarketing.first.article.sizes.all(:select => 'id')
class PortOfDischage < ActiveRecord::Base def _name @_name ||= self.city endend
Reloading...=> true>> p=PortOfDischage.first SQL (0.2ms) SET SQL_AUTO_IS_NULL=0 PortOfDischage Load (21.2ms) SELECT * FROM `port_of_dischages` LIMIT 1 PortOfDischage Columns (1.7ms) SHOW FIELDS FROM `port_of_dischages`+----+------------+-----------------+---------+---------+--------------------------------+--------------------------------+| id | ap_list_id | ap_marketing_id | city | country | created_at | updated_at |+----+------------+-----------------+---------+---------+--------------------------------+--------------------------------+| 1 | 2 | 2 | Piraeus | Greece | Thu Oct 07 07:10:21 +0800 2010 | Thu Oct 07 07:10:21 +0800 2010 |+----+------------+-----------------+---------+---------+--------------------------------+--------------------------------+1 row in set>> p._name=> "Piraeus">> p.update_attribute(:city,'p') SQL (0.2ms) BEGIN ApMarketing Columns (43.0ms) SHOW FIELDS FROM `ap_marketings` ApMarketing Load (18.6ms) SELECT * FROM `ap_marketings` WHERE (`ap_marketings`.`id` = 2) PortOfDischage Update (45.5ms) UPDATE `port_of_dischages` SET `updated_at` = '2010-12-30 13:08:47', `city` = 'p' WHERE `id` = 1 SQL (55.5ms) COMMIT=> true>> p._name=> "Piraeus">> p.city=> "p">> p.reload PortOfDischage Load (0.7ms) SELECT * FROM `port_of_dischages` WHERE (`port_of_dischages`.`id` = 1) +----+------------+-----------------+------+---------+--------------------------------+--------------------------------+| id | ap_list_id | ap_marketing_id | city | country | created_at | updated_at |+----+------------+-----------------+------+---------+--------------------------------+--------------------------------+| 1 | 2 | 2 | p | Greece | Thu Oct 07 07:10:21 +0800 2010 | Thu Dec 30 13:08:47 +0800 2010 |+----+------------+-----------------+------+---------+--------------------------------+--------------------------------+1 row in set>> p._name=> "Piraeus"
p User.first(:order => "RAND()")p User.first(:order => "RAND()")