{"id":12480,"date":"2020-12-26T15:40:21","date_gmt":"2020-12-26T06:40:21","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=12480"},"modified":"2023-05-27T22:42:06","modified_gmt":"2023-05-27T13:42:06","slug":"%e3%80%90ruby-on-rails%e3%80%91%e3%80%8cserialize%e3%80%8d%e3%82%84%e3%80%8cstore%e3%80%8d%e3%81%ab%e3%81%a4%e3%81%84%e3%81%a6","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=12480","title":{"rendered":"\u3010Ruby on Rails\u3011\u300cserialize\u300d\u3084\u300cstore\u300d\u306b\u3064\u3044\u3066"},"content":{"rendered":"<h2>serialize\u3084store\u3068\u306f\uff1f<\/h2>\n<p>ActiveRecord\u306e\u6a5f\u80fd\u306e\u4e00\u3064\u3067text\u578b\u306e\u30ab\u30e9\u30e0\u306b\u5bfe\u3057\u3066\u914d\u5217\u3084\u30cf\u30c3\u30b7\u30e5\u7b49\u597d\u304d\u306a\u30c7\u30fc\u30bf\u578b\u306e\u30c7\u30fc\u30bf\u3092\u653e\u308a\u8fbc\u3080\u3053\u3068\u304c\u3067\u304d\u308b\u6a5f\u80fd\u3067\u3059\u3002<\/p>\n<h2>\u30e1\u30ea\u30c3\u30c8<\/h2>\n<p>\u30c6\u30fc\u30d6\u30eb\u3084\u30ab\u30e9\u30e0\u3092\u8ffd\u52a0\u3057\u306a\u304f\u3066\u3082\u81ea\u7531\u306b\u30c7\u30fc\u30bf\u3092\u4fdd\u5b58\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u4fbf\u5229\u6a5f\u80fd\u306e\u4e8b\u3067\u3059\u3002<\/p>\n<h2>serialize<\/h2>\n<h2>store<\/h2>\n<p>serialize\u306e\u30e9\u30c3\u30d1\u30fc\u3067\u30e2\u30c7\u30eb\u306b\u81ea\u52d5\u7684\u306b\u30a2\u30af\u30bb\u30b5(reader\u3084writer)\u3092\u751f\u3084\u3057\u3066\u304f\u308c\u307e\u3059\u3002<\/p>\n<h2>serialize\u306e\u4f7f\u3044\u65b9<\/h2>\n<h3>\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u30d5\u30a1\u30a4\u30eb\u5074<\/h3>\n<p>text\u578b\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\u4eca\u56de\u306e\u5834\u5408\u3067\u8a00\u3048\u3070<span style=\"color: #ff0000;\"><strong>\u300ct.text :memo\u300d<\/strong><\/span>\u304c\u305d\u308c\u306b\u5f53\u305f\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">class CreateUsers &lt; ActiveRecord::Migration[6.0]\r\n  def change\r\n    create_table :users do |t|\r\n      t.string :name\r\n      t.text :memo\r\n\r\n      t.timestamps\r\n    end\r\n  end\r\nend\r\n<\/pre>\n<h3>\u30e2\u30c7\u30eb\u5074<\/h3>\n<pre class=\"lang:default decode:true\">class User &lt; ApplicationRecord\r\n  serialize :memo\r\nend<\/pre>\n<h3>\u4f7f\u3063\u3066\u307f\u308b\u3002<\/h3>\n<p>\u30ab\u30e9\u30e0\u306b\u914d\u5217\u3092\u767b\u9332\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u3002\u53d6\u308a\u51fa\u3059\u969b\u3082\u914d\u5217\u3068\u3057\u3066\u53d6\u308a\u51fa\u305b\u3066\u3044\u307e\u3059\u3002\u3053\u308c\u306f\u666e\u901a\u306etext\u5f62\u3067\u306f\u7121\u7406\u3067\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">user = User.new\r\nirb(main):007:0&gt; user.name = [123,245]\r\n=&gt; [123, 245]\r\nirb(main):009:0&gt; user.save!\r\n   (0.1ms)  begin transaction\r\n  User Create (0.9ms)  INSERT INTO \"users\" (\"name\", \"memo\", \"created_at\", \"updated_at\") VALUES (?, ?, ?, ?)  [[\"name\", \"[123, 245]\"], [\"memo\", \"---\\n- 123\\n- 245\\n\"], [\"created_at\", \"2020-12-26 07:12:12.364860\"], [\"updated_at\", \"2020-12-26 07:12:12.364860\"]]\r\n\r\nirb(main):014:0&gt; User.all.third.memo[0]\r\n  User Load (0.2ms)  SELECT \"users\".* FROM \"users\" ORDER BY \"users\".\"id\" ASC LIMIT ? OFFSET ?  [[\"LIMIT\", 1], [\"OFFSET\", 2]]\r\n=&gt; 123\r\nirb(main):015:0&gt; User.all.third.memo[1]\r\n  User Load (0.2ms)  SELECT \"users\".* FROM \"users\" ORDER BY \"users\".\"id\" ASC LIMIT ? OFFSET ?  [[\"LIMIT\", 1], [\"OFFSET\", 2]]\r\n=&gt; 245<\/pre>\n<p>\u4e0a\u8a18\u306e\u4f8b\u3092\u898b\u308c\u3070\u308f\u304b\u308b\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u53d6\u308a\u51fa\u3059\u969b\u306b\u300c[123,245]\u300d\u3068\u306a\u3063\u3066\u3044\u307e\u3059\u304cDB\u306b\u306f\u4e0b\u8a18\u306e\u3088\u3046\u306a\u5024\u304c\u683c\u7d0d\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u3053\u308c\u3092Rails\u3067\u306f\u53d6\u308a\u51fa\u3059\u969b\u306b\u914d\u5217\u306b\u5909\u63db\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">---\\n- 123\\n- 245\\n<\/pre>\n<h2>\u57fa\u672c\u7684\u306b\u306f\u4f7f\u308f\u306a\u3044\u3002<\/h2>\n<ul>\n<li>\u666e\u901a\u306e\u6587\u5b57\u5217\u306b\u6bd4\u3079\u3066\u691c\u7d22\u3082\u3057\u3065\u3089\u3044\u3002<\/li>\n<li>\u30ab\u30e9\u30e0\u306b\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u304c\u8cbc\u308c\u306a\u3044\u3002<\/li>\n<li>DB\u306e\u6b63\u898f\u5316\u3092\u305b\u305a\u306b\u30c7\u30fc\u30bf\u3092\u4fdd\u6301\u3059\u308b\u3068\u3044\u3046\u3053\u3068\u306b\u306a\u308b\u306e\u3067RDBMS\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u6d3b\u7528\u3057\u304d\u308c\u306a\u3044\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"serialize\u3084store\u3068\u306f\uff1f ActiveRecord\u306e\u6a5f\u80fd\u306e\u4e00\u3064\u3067text\u578b\u306e\u30ab\u30e9\u30e0\u306b\u5bfe\u3057\u3066\u914d\u5217\u3084\u30cf\u30c3\u30b7\u30e5\u7b49\u597d\u304d\u306a\u30c7\u30fc\u30bf\u578b\u306e\u30c7\u30fc\u30bf\u3092\u653e\u308a\u8fbc\u3080\u3053\u3068\u304c\u3067\u304d\u308b\u6a5f\u80fd\u3067\u3059\u3002 \u30e1\u30ea\u30c3\u30c8 \u30c6\u30fc\u30d6\u30eb\u3084\u30ab\u30e9\u30e0\u3092\u8ffd\u52a0\u3057\u306a\u304f\u3066\u3082\u81ea\u7531 [&hellip;]","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[36],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/12480"}],"collection":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=12480"}],"version-history":[{"count":4,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/12480\/revisions"}],"predecessor-version":[{"id":20492,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/12480\/revisions\/20492"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12480"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12480"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12480"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}