2014/04/29分のコミットです。
ActiveRecord::Associations::CollectionAssociation#delete_all
メソッドのリファクタリングに関するコミットが多くありました。
ActiveRecord::Associations::CollectionAssociation#delete_all
に:nullifyを指定した場合に発行されるSQLが少し変わっています。
rails guideの修正。active_support_instrumentationのページで、end
が足りてなかったのを追加しています。
write a new method to be accessed from delete_all
ActiveRecord::Associations::CollectionAssociation#delete_all
メソッドのリファクタリング。
delete_all
メソッドは引数により処理の分岐が起こるのですが、その分岐処理をdelete
メソッドで行っていたのを、その処理をdelete_all_with_dependency
に切り出して、delete_all
メソッドからはdelete_all_with_dependency
メソッドを呼び出すように修正しています。
知らなかったのですが、delete_all
メソッドに引数指定出来るんですねえ。
User.todos.delete_all(:nullify) # UPDATE "todos" SET "user_id" = NULL WHERE "todos"."user_id" = ? AND "todos"."id" IN (10, 11) [["user_id", 2]] User.todos.delete_all(:delete_all) # DELETE FROM "todos" WHERE "todos"."user_id" = ? AND "todos"."id" IN (12, 13, 14, 15, 16, 17) [["user_id", 2]]
nullify
を引数に指定した場合、DELETE
ではなく、UPDATE
が発行されるんですね。
remove unnecessary code from delete method
上記コミットでdelete_all_with_dependency
を作成した事により、delete
メソッドから不要になった処理を削除しています。
simplify the delete all w/ dependency method
delete_all_with_dependency
をリファクタリングしています。不要な判定処理を削除しています。
[ci skip] updating active_record/associations to demonstrate where conflict with eager loading.
ActiveRecord::Associations
のコメントの修正。LEFT OUTER JOINを使用した場合の例を追加しています。
# If you want to load all posts (including posts with no approved comments) then write # your own LEFT OUTER JOIN query using ON # # Post.joins('LEFT OUTER JOIN comments ON comments.post_id = posts.id AND comments.approved = true') #
flip conditional in delete_all to handle nullify better
上記でコミットされたdelete_all_with_dependency
のリファクタリングです。
:nullifyを指定されている際に、associationsがload済みの場合、発行されるSQLにin statementが含まれるのですが、load済みの場合でも、 in statementが含まれないよう修正しています。
# before UPDATE "categorizations" SET "category_id" = NULL WHERE "categorizations"."category_id" = 1 AND "categorizations"."id" IN (1, 2) # after UPDATE "categorizations" SET "category_id" = NULL WHERE "categorizations"."category_id" = 1
そもそもassociationsがloadされてない場合は、afterの方のSQLが発行されていたので、処理が統一された、と言えない事も無いのですが…。少し違和感が。
rewrite test to correctly test clear method
associations/callbacks_test.rb
の修正です。テストメソッド名を修正しています。
clear shouldnt fire callbacks so remove order test
こちらはactiverecord/test/cases/associations/has_many_through_associations_test.rb
の修正。不要なコードを削除しています。
add test to check that loaded and non laoded are the same
こちらもactiverecord/test/cases/associations/has_many_through_associations_test.rb
の修正。
associationsがload済み/済みでないにかかわらず、同じSQLが発行されるようになったので、そのチェック用のテストコード追加しています。
Update the Getting Started tutorial
rails guideの修正。 Getting Startedを修正しています。
コードサンプルや説明が不足していた部分が大分追加されています。