{"id":1886,"date":"2014-11-18T10:00:02","date_gmt":"2014-11-18T01:00:02","guid":{"rendered":"http:\/\/www.skyarch.net\/blog\/?p=1886"},"modified":"2014-11-17T12:39:14","modified_gmt":"2014-11-17T03:39:14","slug":"doctrine2%e3%81%ae%e5%b0%8f%e3%83%8d%e3%82%bf%e8%a4%87%e6%95%b0%e5%9b%9einsert%e3%81%97%e3%81%9f%e3%81%84%e3%81%a8%e3%81%8d%e7%b7%a8","status":"publish","type":"post","link":"https:\/\/www.skyarch.net\/blog\/doctrine2%e3%81%ae%e5%b0%8f%e3%83%8d%e3%82%bf%e8%a4%87%e6%95%b0%e5%9b%9einsert%e3%81%97%e3%81%9f%e3%81%84%e3%81%a8%e3%81%8d%e7%b7%a8\/","title":{"rendered":"Doctrine2\u306e\u5c0f\u30cd\u30bf(\u8907\u6570\u56deInsert\u3057\u305f\u3044\u3068\u304d\u7de8)"},"content":{"rendered":"<p>\u3053\u3093\u306b\u3061\u308f\u3001\u4eca\u56de\u304b\u3089\u306f\u3001Symfony2\u306b\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u4ed8\u5c5e\u3057\u3066\u3044\u308bORM\u3067\u3042\u308bDoctrine2\u306e\u5c0f\u30cd\u30bf\u3092\u7d39\u4ecb\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002\u534a\u5206\u306f\u5099\u5fd8\u9332\u306b\u306a\u308a\u307e\u3059<\/p>\n<p>\u4eca\u65e5\u306f\u3001\u4e00\u5ea6\u306b\u591a\u6570\u306e\u30c7\u30fc\u30bf\u3092\u633f\u5165\u3057\u305f\u3044\u3068\u304d\u306f\u3069\u3046\u3059\u308b\u306e\uff1f\u3067\u3059\u3002\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\u306f<br \/>\n<a href=\"http:\/\/docs.symfony.gr.jp\/symfony2\/book\/doctrine.html\" title=\"http:\/\/docs.symfony.gr.jp\/symfony2\/book\/doctrine.html\" target=\"_blank\">http:\/\/docs.symfony.gr.jp\/symfony2\/book\/doctrine.html<\/a>\u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h1>\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3<\/h1>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nuse Doctrine\\ORM\\Mapping as ORM;\r\n\r\n\/**\r\n * @ORM\\Entity\r\n * @ORM\\Table(name=&quot;product&quot;)\r\n *\/\r\nclass Product\r\n{\r\n    \/**\r\n     * @ORM\\Id\r\n     * @ORM\\Column(type=&quot;integer&quot;)\r\n     * @ORM\\GeneratedValue(strategy=&quot;AUTO&quot;)\r\n     *\/\r\n    protected $id;\r\n\r\n    \/**\r\n     * @ORM\\Column(type=&quot;string&quot;, length=100)\r\n     *\/\r\n    protected $name;\r\n\r\n    \/**\r\n     * @ORM\\Column(type=&quot;decimal&quot;, scale=2)\r\n     *\/\r\n    protected $price;\r\n\r\n    \/**\r\n     * @ORM\\Column(type=&quot;text&quot;)\r\n     *\/\r\n    protected $description;\r\n}\r\n<\/pre>\n<p>\u516c\u5f0f\u30da\u30fc\u30b8\u306e\u307e\u307e\u5229\u7528\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u3053\u3061\u3089\u3092\u666e\u901a\u306bInsert\u3059\u308b\u3068\u304d\u306f<\/p>\n<h1>\u5358\u72ecInsert<\/h1>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\npublic function createAction()\r\n{\r\n    $product = new Product();\r\n    $product-&gt;setName('A Foo Bar');\r\n    $product-&gt;setPrice('19.99');\r\n    $product-&gt;setDescription('Lorem ipsum dolor');\r\n\r\n    $em = $this-&gt;getDoctrine()-&gt;getEntityManager();\r\n    $em-&gt;persist($product);\r\n    $em-&gt;flush();\r\n\r\n    return new Response('Created product');\r\n}\r\n<\/pre>\n<p>\u3067\u3059\u3001\u3067\u306f\u3001\u8907\u6570\u500b\u306eProduct\u3092\u540c\u6642\u306bInsert\u3059\u308b\u5834\u5408\u306f\u3069\u3046\u3059\u308c\u3070\u3088\u3044\u3067\u3057\u3087\u3046\u3002<br \/>\n\u30dd\u30a4\u30f3\u30c8\u306f\u3001Doctrine2\u306e\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u30de\u30cd\u30fc\u30b8\u30e3\u30fc\u306f<\/p>\n<ul>\n<li>persist\u3067\u306f\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u7ba1\u7406\u4e0b\u306b\u304a\u304f\u3060\u3051<\/li>\n<li>flush\u3067\u7ba1\u7406\u3057\u3066\u3044\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u5bfe\u5fdc\u3057\u305f\u3001SQL\u6587\u3092\u767a\u884c\u3059\u308b<\/li>\n<\/ul>\n<p>\u3068\u3044\u3046\u70b9\u3067\u3059\u3001\u3053\u308c\u306b\u5f93\u3063\u3066\u66f8\u3044\u3066\u307f\u307e\u3057\u3087\u3046<\/p>\n<h1>\u8907\u6570Insert<\/h1>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\npublic function createManyAction()\r\n{\r\n    $em = $this-&gt;getDoctrine()-&gt;getEntityManager();\r\n    $names        = Array(&quot;a&quot;, &quot;b&quot;);\r\n    $prices       = Array(100, 200);\r\n    $descriptions = Array(&quot;hello&quot;, &quot;goodbye&quot;);\r\n    for($i = 0; $i &lt; 2; $i++){\r\n        $product = new Product();\r\n        $product-&gt;setName($names&#x5B;$i]);\r\n        $product-&gt;setPrice($prices&#x5B;$i]);\r\n        $product-&gt;setDescription($descriptions&#x5B;$i]);\r\n        $em-&gt;persist($product);\r\n    }\r\n    $em-&gt;flush();\r\n\r\n    return new Response('Created products');\r\n}\r\n<\/pre>\n<p>\u3068\u306a\u308a\u307e\u3059\u3002persist\u306b\u306fPDO\u3067\u3044\u3046prepare\u306e\u5f79\u5272\u3082\u3042\u308b\u306e\u3067\u3001\u3053\u306e\u65b9\u6cd5\u3060\u3068\u30af\u30a8\u30ea\u30fc\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u6709\u52b9\u306b\u5229\u7528\u3067\u304d\u308b\u305d\u3046\u3067\u3059\u3002<a href=\"http:\/\/doctrine-orm.readthedocs.org\/en\/latest\/reference\/batch-processing.html?highlight=batch\" title=\"http:\/\/doctrine-orm.readthedocs.org\/en\/latest\/reference\/batch-processing.html?highlight=batch\" target=\"_blank\">http:\/\/doctrine-orm.readthedocs.org\/en\/latest\/reference\/batch-processing.html?highlight=batch<\/a>\u306a\u3069\u304c\u53c2\u8003\u306b\u306a\u308b\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n<p>\u4e00\u6c17\u306bInsert\u3059\u308b\u306e\u3067\u306f\u306a\u304f\u3001for\u306e\u4e2d\u3067Insert\u3092\u5b9f\u884c\u3057\u305f\u3044\u5834\u5408\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059<\/p>\n<h1>\u8907\u6570Insert1\u56de\u3054\u3068<\/h1>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\npublic function createManyAction()\r\n{\r\n    $em = $this-&gt;getDoctrine()-&gt;getEntityManager();\r\n    $names        = Array(&quot;a&quot;, &quot;b&quot;);\r\n    $prices       = Array(100, 200);\r\n    $descriptions = Array(&quot;hello&quot;, &quot;goodbye&quot;);\r\n    for($i = 0; $i &lt; 2; $i++){\r\n        $product = new Product();\r\n        $product-&gt;setName($names&#x5B;$i]);\r\n        $product-&gt;setPrice($prices&#x5B;$i]);\r\n        $product-&gt;setDescription($descriptions&#x5B;$i]);\r\n        $em-&gt;persist($product);\r\n        $em-&gt;flush();\r\n        $em-&gt;clear();\r\n    }\r\n\r\n    return new Response('Created products');\r\n}\r\n<\/pre>\n<p>SQL\u3092\u767a\u884c\u3059\u308b\u305f\u3073\u306b\u3001\u7ba1\u7406\u3059\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u30af\u30ea\u30a2\u3057\u3066\u3044\u308b\u70b9\u304c\u30dd\u30a4\u30f3\u30c8\u3067\u3059\u3002<\/p>\n<p>\u4eca\u56de\u306f\u3053\u308c\u3067\u5931\u793c\u3044\u305f\u3057\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u3093\u306b\u3061\u308f\u3001\u4eca\u56de\u304b\u3089\u306f\u3001Symfony2\u306b\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u4ed8\u5c5e\u3057\u3066\u3044\u308bORM\u3067\u3042\u308bDoctrine2\u306e\u5c0f\u30cd\u30bf\u3092\u7d39\u4ecb\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002\u534a\u5206\u306f\u5099\u5fd8\u9332\u306b\u306a\u308a\u307e\u3059 \u4eca\u65e5\u306f\u3001\u4e00\u5ea6\u306b\u591a\u6570\u306e\u30c7\u30fc\u30bf\u3092\u633f\u5165\u3057\u305f\u3044\u3068\u304d\u306f\u3069\u3046\u3059\u308b\u306e\uff1f\u3067\u3059\u3002\u57fa\u672c\u7684&#8230;<\/p>\n","protected":false},"author":34,"featured_media":1999,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"","_original_post":"","footnotes":""},"categories":[23,9],"tags":[],"class_list":{"0":"post-1886","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-23","8":"category-dev","9":"ja"},"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts\/1886","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/users\/34"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/comments?post=1886"}],"version-history":[{"count":5,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts\/1886\/revisions"}],"predecessor-version":[{"id":1891,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts\/1886\/revisions\/1891"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/media\/1999"}],"wp:attachment":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/media?parent=1886"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/categories?post=1886"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/tags?post=1886"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}