{"id":918,"date":"2010-02-23T17:31:43","date_gmt":"2010-02-23T08:31:43","guid":{"rendered":"http:\/\/ecpplus.net\/weblog\/?p=918"},"modified":"2020-06-15T22:06:51","modified_gmt":"2020-06-15T13:06:51","slug":"rails-%e3%81%ae-dynamic-scopes-%e3%81%a7%e3%81%ae-delete_all-%e3%81%af%e5%a4%96%e9%83%a8%e3%82%ad%e3%83%bc%e3%82%92-null-%e3%81%ab%e3%81%99%e3%82%8b%e3%81%a0%e3%81%91","status":"publish","type":"post","link":"https:\/\/ecpplus.net\/weblog\/rails-%e3%81%ae-dynamic-scopes-%e3%81%a7%e3%81%ae-delete_all-%e3%81%af%e5%a4%96%e9%83%a8%e3%82%ad%e3%83%bc%e3%82%92-null-%e3%81%ab%e3%81%99%e3%82%8b%e3%81%a0%e3%81%91\/","title":{"rendered":"Rails \u306e Dynamic Scopes \u3067\u306e delete_all \u306f\u5916\u90e8\u30ad\u30fc\u3092 NULL \u306b\u3059\u308b\u3060\u3051"},"content":{"rendered":"<p>Shop has_many Items \u3068\u3044\u3046\u72b6\u6cc1\u306e\u3068\u304d\u3001\u3068\u3042\u308b shop \u304c\u6301\u3063\u3066\u3044\u308b items \u3092\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306b\u53d6\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002\u305d\u308c\u306b\u5bfe\u3057\u3066\u3001\u6761\u4ef6\u3092\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u3082\u51fa\u6765\u307e\u3059\u3002<\/p>\n<pre lang=\"ruby\">>> @shop.items \n=> [Item id:21 shop_id: 1, Item id: 22, shop_id: 1, ....]\n>> @shop.item.find_all_by_category(\"CPU\") \n=> [Item id:23 shop_id: 1, Item id: 26, shop_id: 1, ....]\n<\/pre>\n<p>\u305d\u3053\u3067\u3001\u540c\u69d8\u306b\u3068\u3042\u308b Shop \u306e Items \u3092\u5168\u90e8 delete_all \u306b\u3057\u3088\u3046\u3068\u3057\u305f\u306e\u3067\u3059\u304c\u3001DELETE \u3055\u308c\u308b\u306e\u3067\u306f\u306a\u304f\u3001\u5916\u90e8\u30ad\u30fc\u306bNULL\u304c\u30bb\u30c3\u30c8\u3055\u308c\u308b\u3068\u3044\u3046\u6319\u52d5\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre lang=\"ruby\">>> @shop.items.delete_all<\/pre>\n<p>\u3068\u3059\u308b\u3068<\/p>\n<pre lang=\"sql\">  Item Update (3.0ms)   UPDATE `items` SET shop_id = NULL WHERE (shop_id = 1 AND id IN (22,23,24,25,26)) <\/pre>\n<p>\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>Rails \u306e API \u3092\u898b\u308b\u3068<\/p>\n<pre lang=\"ruby\"># File vendor\/rails\/activerecord\/lib\/active_record\/base.rb, line 897\n897:       def delete_all(conditions = nil)\n898:         sql = \"DELETE FROM #{quoted_table_name} \"\n899:         add_conditions!(sql, conditions, scope(:find))\n900:         connection.delete(sql, \"#{name} Delete all\")\n901:       end<\/pre>\n<p>\u307f\u305f\u3044\u306b\u306a\u3063\u3066\u3044\u308b\u306e\u3067\u3059\u304c\u3001Dynamic Scopes \u306f\u307e\u305f\u5225\u306e\u3068\u3053\u308d\u3067\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u3063\u307d\u3044\u3067\u3059\u3002<\/p>\n<pre lang=\"ruby\">>> @shop.items.destroy_all<\/pre>\n<p>\u3068\u3057\u3066\u307f\u308b\u3068\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306b DELETE \u306b\u306a\u308a\u307e\u3059\u304c\u3001SQL \u304c\u767a\u884c\u3055\u308c\u307e\u304f\u3063\u3066\u308b\u306e\u3067\u3060\u3081\u307d\u3044\u3067\u3059\u3002\u305d\u3082\u305d\u3082 destroy \u306f\u3001destroy \u3092\u30c8\u30ea\u30ac\u30fc\u306b\u3057\u3066\u3044\u308b\u5404\u7a2e\u51e6\u7406\u3092\u3057\u3066\u304b\u3089 DELETE \u304c\u884c\u308f\u308c\u308b\u306e\u3067\u3001\u305d\u3082\u305d\u3082 delete \u3068\u306f\u610f\u5473\u5408\u3044\u304c\u9055\u3046\u3068\u3044\u3046\u306e\u3067\u4ed5\u65b9\u306a\u3044\u3067\u3059\u3002<\/p>\n<pre lang=\"sql\">Item Destroy (3.0ms)   DELETE FROM `items` WHERE WHERE id = 21\nItem Destroy (3.0ms)   DELETE FROM `items` WHERE WHERE id = 22\nItem Destroy (3.0ms)   DELETE FROM `items` WHERE WHERE id = 23<\/pre>\n<p>\u3075\u3064\u3046\u306b Item.delete_all \u3092\u547c\u3076\u304b\u306a\u3041<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Shop has_many Items \u3068\u3044\u3046\u72b6\u6cc1\u306e\u3068\u304d\u3001\u3068\u3042\u308b shop \u304c\u6301\u3063\u3066\u3044\u308b items \u3092\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306b\u53d6\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002\u305d\u308c\u306b\u5bfe\u3057\u3066\u3001\u6761\u4ef6\u3092\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u3082\u51fa\u6765\u307e\u3059\u3002 >> @shop.items =>  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2521,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[10],"class_list":["post-918","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-development","tag-rails"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.10 - aioseo.com -->\n\t<meta name=\"description\" content=\"Shop has_many Items \u3068\u3044\u3046\u72b6\u6cc1\u306e\u3068\u304d\u3001\u3068\u3042\u308b shop \u304c\u6301\u3063\u3066\u3044\u308b items \u3092\u3001\u4e0b\u8a18\" \/>\n\t<meta name=\"robots\" content=\"max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n\t<meta name=\"author\" content=\"\u3061\u3085\u3046\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/ecpplus.net\/weblog\/rails-%e3%81%ae-dynamic-scopes-%e3%81%a7%e3%81%ae-delete_all-%e3%81%af%e5%a4%96%e9%83%a8%e3%82%ad%e3%83%bc%e3%82%92-null-%e3%81%ab%e3%81%99%e3%82%8b%e3%81%a0%e3%81%91\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.10\" \/>\n\t\t<meta property=\"og:locale\" content=\"ja_JP\" \/>\n\t\t<meta property=\"og:site_name\" content=\"\u5909\u306a\u30e4\u30d0\u3044\u3082\u3093\u30ed\u30b0\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Rails \u306e Dynamic Scopes \u3067\u306e delete_all \u306f\u5916\u90e8\u30ad\u30fc\u3092 NULL \u306b\u3059\u308b\u3060\u3051 | \u5909\u306a\u30e4\u30d0\u3044\u3082\u3093\u30ed\u30b0\" \/>\n\t\t<meta property=\"og:description\" content=\"Shop has_many Items \u3068\u3044\u3046\u72b6\u6cc1\u306e\u3068\u304d\u3001\u3068\u3042\u308b shop \u304c\u6301\u3063\u3066\u3044\u308b items \u3092\u3001\u4e0b\u8a18\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/ecpplus.net\/weblog\/rails-%e3%81%ae-dynamic-scopes-%e3%81%a7%e3%81%ae-delete_all-%e3%81%af%e5%a4%96%e9%83%a8%e3%82%ad%e3%83%bc%e3%82%92-null-%e3%81%ab%e3%81%99%e3%82%8b%e3%81%a0%e3%81%91\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/ecpplus.net\/weblog\/wp-content\/uploads\/2011\/08\/ruby_on_rails.png\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/ecpplus.net\/weblog\/wp-content\/uploads\/2011\/08\/ruby_on_rails.png\" \/>\n\t\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t\t<meta property=\"og:image:height\" content=\"768\" \/>\n\t\t<meta property=\"article:tag\" content=\"development\" \/>\n\t\t<meta property=\"article:tag\" content=\"rails\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2010-02-23T08:31:43+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2020-06-15T13:06:51+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@ecpplus\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Rails \u306e Dynamic Scopes \u3067\u306e delete_all \u306f\u5916\u90e8\u30ad\u30fc\u3092 NULL \u306b\u3059\u308b\u3060\u3051 | \u5909\u306a\u30e4\u30d0\u3044\u3082\u3093\u30ed\u30b0\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Shop has_many Items \u3068\u3044\u3046\u72b6\u6cc1\u306e\u3068\u304d\u3001\u3068\u3042\u308b shop \u304c\u6301\u3063\u3066\u3044\u308b items \u3092\u3001\u4e0b\u8a18\" \/>\n\t\t<meta name=\"twitter:creator\" content=\"@ecpplus\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/ecpplus.net\/weblog\/wp-content\/uploads\/2011\/08\/ruby_on_rails.png\" \/>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Rails \u306e Dynamic Scopes \u3067\u306e delete_all \u306f\u5916\u90e8\u30ad\u30fc\u3092 NULL \u306b\u3059\u308b\u3060\u3051 | \u5909\u306a\u30e4\u30d0\u3044\u3082\u3093\u30ed\u30b0","description":"Shop has_many Items \u3068\u3044\u3046\u72b6\u6cc1\u306e\u3068\u304d\u3001\u3068\u3042\u308b shop \u304c\u6301\u3063\u3066\u3044\u308b items \u3092\u3001\u4e0b\u8a18","canonical_url":"https:\/\/ecpplus.net\/weblog\/rails-%e3%81%ae-dynamic-scopes-%e3%81%a7%e3%81%ae-delete_all-%e3%81%af%e5%a4%96%e9%83%a8%e3%82%ad%e3%83%bc%e3%82%92-null-%e3%81%ab%e3%81%99%e3%82%8b%e3%81%a0%e3%81%91\/","robots":"max-snippet:-1, max-image-preview:large, max-video-preview:-1","keywords":"","webmasterTools":{"miscellaneous":""},"schema":null,"og:locale":"ja_JP","og:site_name":"\u5909\u306a\u30e4\u30d0\u3044\u3082\u3093\u30ed\u30b0","og:type":"article","og:title":"Rails \u306e Dynamic Scopes \u3067\u306e delete_all \u306f\u5916\u90e8\u30ad\u30fc\u3092 NULL \u306b\u3059\u308b\u3060\u3051 | \u5909\u306a\u30e4\u30d0\u3044\u3082\u3093\u30ed\u30b0","og:description":"Shop has_many Items \u3068\u3044\u3046\u72b6\u6cc1\u306e\u3068\u304d\u3001\u3068\u3042\u308b shop \u304c\u6301\u3063\u3066\u3044\u308b items \u3092\u3001\u4e0b\u8a18","og:url":"https:\/\/ecpplus.net\/weblog\/rails-%e3%81%ae-dynamic-scopes-%e3%81%a7%e3%81%ae-delete_all-%e3%81%af%e5%a4%96%e9%83%a8%e3%82%ad%e3%83%bc%e3%82%92-null-%e3%81%ab%e3%81%99%e3%82%8b%e3%81%a0%e3%81%91\/","og:image":"https:\/\/ecpplus.net\/weblog\/wp-content\/uploads\/2011\/08\/ruby_on_rails.png","og:image:secure_url":"https:\/\/ecpplus.net\/weblog\/wp-content\/uploads\/2011\/08\/ruby_on_rails.png","og:image:width":1920,"og:image:height":768,"article:tag":["development","rails"],"article:published_time":"2010-02-23T08:31:43+00:00","article:modified_time":"2020-06-15T13:06:51+00:00","twitter:card":"summary_large_image","twitter:site":"@ecpplus","twitter:title":"Rails \u306e Dynamic Scopes \u3067\u306e delete_all \u306f\u5916\u90e8\u30ad\u30fc\u3092 NULL \u306b\u3059\u308b\u3060\u3051 | \u5909\u306a\u30e4\u30d0\u3044\u3082\u3093\u30ed\u30b0","twitter:description":"Shop has_many Items \u3068\u3044\u3046\u72b6\u6cc1\u306e\u3068\u304d\u3001\u3068\u3042\u308b shop \u304c\u6301\u3063\u3066\u3044\u308b items \u3092\u3001\u4e0b\u8a18","twitter:creator":"@ecpplus","twitter:image":"https:\/\/ecpplus.net\/weblog\/wp-content\/uploads\/2011\/08\/ruby_on_rails.png"},"aioseo_meta_data":{"post_id":"918","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":"","og_description":"","og_object_type":"article","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":"","og_article_tags":"","twitter_use_og":false,"twitter_card":"summary_large_image","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2021-01-02 12:52:45","updated":"2022-09-29 11:10:20","seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/ecpplus.net\/weblog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/ecpplus.net\/weblog\/category\/development\/\" title=\"Development\">Development<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tRails \u306e Dynamic Scopes \u3067\u306e delete_all \u306f\u5916\u90e8\u30ad\u30fc\u3092 NULL \u306b\u3059\u308b\u3060\u3051\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/ecpplus.net\/weblog"},{"label":"Development","link":"https:\/\/ecpplus.net\/weblog\/category\/development\/"},{"label":"Rails \u306e Dynamic Scopes \u3067\u306e delete_all \u306f\u5916\u90e8\u30ad\u30fc\u3092 NULL \u306b\u3059\u308b\u3060\u3051","link":"https:\/\/ecpplus.net\/weblog\/rails-%e3%81%ae-dynamic-scopes-%e3%81%a7%e3%81%ae-delete_all-%e3%81%af%e5%a4%96%e9%83%a8%e3%82%ad%e3%83%bc%e3%82%92-null-%e3%81%ab%e3%81%99%e3%82%8b%e3%81%a0%e3%81%91\/"}],"_links":{"self":[{"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/posts\/918","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/comments?post=918"}],"version-history":[{"count":2,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/posts\/918\/revisions"}],"predecessor-version":[{"id":2533,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/posts\/918\/revisions\/2533"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/media\/2521"}],"wp:attachment":[{"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/media?parent=918"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/categories?post=918"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/tags?post=918"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}