2008年9月1日 星期一

model, include, left outer join


>>User.find(:all, :include => 'profile')
User Load (0.000682) SELECT * FROM `users`
Profile Load (0.000492) SELECT `profiles`.* FROM `profiles` WHERE (`profiles`.user_id IN (1,2,4,5))
Profile Columns (0.000880) SHOW FIELDS FROM `profiles`


>> User.find(:all, :include => 'profile', :conditions => "users.name is not NULL")
User Load (0.000731) SELECT * FROM `users` WHERE (users.name is not NULL)
Profile Load (0.000183) SELECT `profiles`.* FROM `profiles` WHERE (`profiles`.user_id IN (1,2,4,5))


User.find(:all, :include => 'profile', :conditions => "profiles.others is NULL")
User Load Including Associations (0.001349) SELECT `users`.`id` AS t0_r0, `users`.`name` AS t0_r1, `users`.
`password_salt` AS t0_r2, `users`.`password_hash` AS t0_r3, `users`.`email` AS t0_r4, `users`.`created_at` AS t
0_r5, `users`.`cookie_hash` AS t0_r6, `users`.`target_time_now` AS t0_r7, `users`.`reset_password_code` AS t0_r
8, `users`.`reset_password_code_until` AS t0_r9, `users`.`yahoo_userhash` AS t0_r10, `users`.`group_id` AS t0_r
11, `users`.`group_nickname` AS t0_r12, `users`.`time_zone` AS t0_r13, `profiles`.`id` AS t1_r0, `profiles`.`user_id` AS t1_r1, `profiles`.`others` AS t1_r2, `profiles`.`sex` AS t1_r3, `profiles`.`birth` AS t1_r4, `profiles`.`star` AS t1_r5, `profiles`.`blood` AS t1_r6, `profiles`.`address` AS t1_r7, `profiles`.`school` AS t1_r8, `profiles`.`job` AS t1_r9, `profiles`.`interest` AS t1_r10, `profiles`.`photo` AS t1_r11, `profiles`.`connect` AS t1_r12, `profiles`.`email_weekly` AS t1_r13 FROM `users` LEFT OUTER JOIN `profiles` ON profiles.user_id = users.id WHERE (profiles.others is NULL)


沒有留言: