{"id":476,"date":"2008-04-24T03:26:06","date_gmt":"2008-04-23T18:26:06","guid":{"rendered":"http:\/\/ecpplus.net\/weblog\/?p=476"},"modified":"2020-06-15T22:18:49","modified_gmt":"2020-06-15T13:18:49","slug":"skip_validation_on_active_record","status":"publish","type":"post","link":"https:\/\/ecpplus.net\/weblog\/skip_validation_on_active_record\/","title":{"rendered":"AR\u3067Validation\u3092Skip\u3057\u3066\u4fdd\u5b58\u3059\u308b"},"content":{"rendered":"<p>\u3000AJAX\u3067\u51e6\u7406\u66f8\u304f\u3068\u3001\u3069\u3046\u3057\u3066\u3082Create\u306e\u6642\u306f\u30c7\u30fc\u30bf\u304c\u4e0d\u5b8c\u5168\u3067\u3082\u3068\u308a\u3042\u3048\u305a\u4f5c\u308a\u305f\u3044\u3002\u307f\u305f\u3044\u306a\u3053\u3068\u304c\u3042\u3063\u3066\u3001\u305d\u308c\u306f <code>validate_on_create, validate_on_update<\/code> \u3067\u5206\u3051\u305f\u308a\u3001\u5404 <code>validates_on_** :on =&gt; :update<\/code> \u307f\u305f\u3044\u306a\u611f\u3058\u306b\u304b\u3051\u3070\u3044\u3044\u3093\u3060\u3051\u3069\u3001<code>sortable_list<\/code> \u3068\u304b\u3067\u5358\u4e00\u30d5\u30a3\u30fc\u30eb\u30c9\u3060\u3051\u3054\u306b\u3087\u3054\u306b\u3087\u3084\u308a\u305f\u3044\u3068\u304d\u306f\u7d50\u69cb\u56f0\u308b\u3002<\/p>\n<p>\u3000\u305d\u3093\u306a\u3068\u304d\u306b\u4f7f\u3048\u305d\u3046\u306a\u30e1\u30bd\u30c3\u30c9\u3002\u304c\u3042\u3063\u305f\u3093\u3060\u3051\u3069\u3001\u7279\u306b\u5fc5\u8981\u304c\u306a\u304b\u3063\u305f\u3053\u3068\u304c\u308f\u304b\u3063\u305f\u3068\u3044\u3046\u8a71\u3002<\/p>\n<h3>activerecord-2.0.2\/lib\/active_record\/validations.rb : line 932<\/h3>\n<p>\u5f15\u6570\u306bfalse\u6e21\u305b\u3070\u3001Validation\u3092\u30b9\u30ad\u30c3\u30d7\u3057\u3066save\u51fa\u6765\u308b\u3002<\/p>\n<pre><code class=\"language-ruby line-numbers\">    # The validation process on save can be skipped by passing false. The regular Base#save method is\n    # replaced with this when the validations module is mixed in, which it is by default.\n    def save_with_validation(perform_validation = true)\n      if perform_validation &amp;&amp; valid? || !perform_validation\n        save_without_validation\n      else\n        false\n      end\n    end\n<\/code><\/pre>\n<h3>activerecord-2.0.2\/lib\/active_record\/validations.rb : line 953<\/h3>\n<p>\u3000\u3053\u3063\u3061\u306f\u3001update_attribute \u306eValidation\u7121\u3057\u7248\u3002<\/p>\n<pre><code class=\"language-ruby line-numbers\">    # Updates a single attribute and saves the record without going through the normal validation procedure.\n    # This is especially useful for boolean flags on existing records. The regular +update_attribute+ method\n    # in Base is replaced with this when the validations module is mixed in, which it is by default.\n    def update_attribute_with_validation_skipping(name, value)\n      send(name.to_s + '=', value)\n      save(false)\n    end\n<\/code><\/pre>\n<p>\u3068\u601d\u3063\u3066\u30bd\u30fc\u30b9\u3092\u898b\u3066\u307f\u305f\u3093\u3060\u3051\u3069\u3001save(false) \u3063\u3066\u66f8\u3044\u3066\u3042\u3063\u3066\u3001\u3069\u3046\u307f\u3066\u3082 Validation\u3092Skip\u3059\u308b\u65b9\u6cd5\u3067\u3057\u305f\u3002<\/p>\n<p><strong>validation \u3092 skip \u3057\u3066 save \u3059\u308b\u3068\u304d\u306f \u5f15\u6570\u306b false \u3092\u6e21\u3059 save(false) \u3068\u3044\u3046\u3053\u3068\u3089\u3057\u3044\u3002<\/strong><\/p>\n<p><code>update_attribute_with_validation_skipping(name, value)<\/code> \u3068\u304b\u306f\u3001\u3071\u3063\u3068\u307f\u3066\u4f55\u3084\u3063\u3066\u308b\u304b\u308f\u304b\u308b\u3093\u3060\u3051\u3069\u3001 <code>save_with_validation(false)<\/code> \u306f\u4e00\u898b\u3057\u3066\u4f55\u3057\u3066\u308b\u304b\u5206\u304b\u308a\u306b\u304f\u3044\u3051\u3069\u3001 <code>save(false)<\/code> \u3092\u77e5\u3089\u306a\u3044\u306a\u3089\u3069\u3063\u3061\u898b\u3066\u3082\u5206\u304b\u3089\u306a\u3044\u304b\u3089\u304b\u308f\u3089\u3093\u306d\u30fc\u3002\u3068\u601d\u3063\u305f\u3088\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3000AJAX\u3067\u51e6\u7406\u66f8\u304f\u3068\u3001\u3069\u3046\u3057\u3066\u3082Create\u306e\u6642\u306f\u30c7\u30fc\u30bf\u304c\u4e0d\u5b8c\u5168\u3067\u3082\u3068\u308a\u3042\u3048\u305a\u4f5c\u308a\u305f\u3044\u3002\u307f\u305f\u3044\u306a\u3053\u3068\u304c\u3042\u3063\u3066\u3001\u305d\u308c\u306f validate_on_create, validate_on_update \u3067\u5206\u3051\u305f\u308a\u3001\u5404 val [&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-476","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-development","tag-rails"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/posts\/476","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=476"}],"version-history":[{"count":3,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/posts\/476\/revisions"}],"predecessor-version":[{"id":2560,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/posts\/476\/revisions\/2560"}],"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=476"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/categories?post=476"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/tags?post=476"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}