{"id":1975,"date":"2014-11-20T14:59:00","date_gmt":"2014-11-20T05:59:00","guid":{"rendered":"http:\/\/www.skyarch.net\/blog\/?p=1975"},"modified":"2014-11-17T12:39:55","modified_gmt":"2014-11-17T03:39:55","slug":"doctrine2%e3%81%ae%e5%b0%8f%e3%83%8d%e3%82%bf%e3%83%87%e3%83%bc%e3%82%bf%e3%83%99%e3%83%bc%e3%82%b9%e3%81%8b%e3%82%89%e3%82%a8%e3%83%b3%e3%83%86%e3%82%a3%e3%83%86%e3%82%a3%e3%82%92%e4%bd%9c%e3%82%8b","status":"publish","type":"post","link":"https:\/\/www.skyarch.net\/blog\/doctrine2%e3%81%ae%e5%b0%8f%e3%83%8d%e3%82%bf%e3%83%87%e3%83%bc%e3%82%bf%e3%83%99%e3%83%bc%e3%82%b9%e3%81%8b%e3%82%89%e3%82%a8%e3%83%b3%e3%83%86%e3%82%a3%e3%83%86%e3%82%a3%e3%82%92%e4%bd%9c%e3%82%8b\/","title":{"rendered":"Doctrine2\u306e\u5c0f\u30cd\u30bf(\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304b\u3089\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u3092\u4f5c\u308b\uff06\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u306e\u7d99\u627f\u7de8)"},"content":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u3001\u4eca\u56de\u306f<\/p>\n<ul>\n<li>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u30c6\u30fc\u30d6\u30eb\u5b9a\u7fa9\u304b\u3089\u3001\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u3092\u4f5c\u6210\u3059\u308b\u65b9\u6cd5\u3002<\/li>\n<li>\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u30af\u30e9\u30b9\u3092\u7d99\u627f\u95a2\u4fc2\u3092\u7528\u3044\u3066\u6d3b\u7528\u3059\u308b\u65b9\u6cd5\u3002<\/li>\n<\/ul>\n<p>\u3092\u89e3\u8aac\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u65e2\u5b58\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092Symfony2\u306b\u79fb\u884c\u3059\u308b\u5834\u5408\u306b\u5f79\u306b\u7acb\u3064\u306e\u3067\u306f\u306a\u3044\u3067\u3057\u3087\u3046\u304b\uff1f<\/p>\n<h1>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u30c6\u30fc\u30d6\u30eb\u5b9a\u7fa9\u304b\u3089\u3001\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u3092\u4f5c\u6210\u3059\u308b\u65b9\u6cd5<\/h1>\n<p>\u5b9f\u306f\u3001<a href=\"http:\/\/docs.symfony.gr.jp\/symfony2\/cookbook\/doctrine\/reverse_engineering.html\" title=\"\u65e2\u306b\u3042\u308b\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304b\u3089\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u3092\u751f\u6210\u3059\u308b\u65b9\u6cd5\">\u65e2\u306b\u3042\u308b\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304b\u3089\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u3092\u751f\u6210\u3059\u308b\u65b9\u6cd5<\/a>\u3068\u3044\u3046\u516c\u5f0f\u30da\u30fc\u30b8\u3067\u3059\u3067\u306b\u89e3\u8aac\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u304c\u3001Annotation\u3067\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u3092\u7ba1\u7406\u3059\u308b\u5834\u5408\u3001<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nphp app\/console doctrine:mapping:import --force AcmeBlogBundle xml\r\n<\/pre>\n<p>\u3060\u3068Xml\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u3066\u3057\u307e\u3044\u3001annotation\u304c\u7121\u52b9\u3068\u306a\u3063\u3066\u3057\u307e\u3046(xml\u306b\u3088\u308b\u8a2d\u5b9a\u3068anntation\u306b\u3088\u308b\u8a2d\u5b9a\u306f\u5171\u5b58\u3067\u304d\u306a\u3044)\u554f\u984c\u304c\u767a\u751f\u3057\u3066\u3057\u307e\u3044\u307e\u3059\u3002<br \/>\n\u306a\u306e\u3067\u3001<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nphp app\/console doctrine:mapping:convert annotation .\/src --from-database --namespace=&quot;Acme\\BlogBundle\\Entity\\\\&quot;\r\nphp app\/console doctrine:generate:entities AcmeBlogBundle\r\n<\/pre>\n<p>\u3068\u3057\u305f\u65b9\u304c\u3001\u521d\u3081\u304b\u3089Annotaion\u4ed8\u304d\u306e\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u304c\u4f5c\u6210\u3055\u308c\u308b\u306e\u3067\u3001\u3088\u3044\u3067\u3059\u3002namespace\u306e\u6700\u5f8c\u306e\u30d0\u30c3\u30af\u30b9\u30e9\u30c3\u30b7\u30e5\u306e2\u91cd\u306f\u30c0\u30d6\u30eb\u30af\u30a9\u30fc\u30c6\u30fc\u30b7\u30e7\u30f3\u306e\u30a8\u30b9\u30b1\u30fc\u30d7\u3092\u907f\u3051\u3001\u30d0\u30c3\u30af\u30b9\u30e9\u30c3\u30b7\u30e5\u3092\u6587\u5b57\u5217\u3068\u3057\u3066\u8a8d\u8b58\u3055\u305b\u308b\u305f\u3081\u3067\u3059\u3002<br \/>\n\u7d50\u679c\u3001src\/Acme\/BlogBundle\/Entity\/\u306b\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u30af\u30e9\u30b9\u304c\u4f5c\u6210\u3055\u308c\u307e\u3059\u3002<\/p>\n<h1>\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u30af\u30e9\u30b9\u3092\u7d99\u627f\u95a2\u4fc2\u3092\u7528\u3044\u3066\u6d3b\u7528\u3059\u308b\u65b9<\/h1>\n<p>\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u306f\u3001Doctrine2\u3067\u306f\u3001PHP\u306e\u30af\u30e9\u30b9\u3068\u3057\u3066\u4f5c\u6210\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u3001\u7d99\u627f\u306a\u3069\u3001PHP\u306e\u30af\u30e9\u30b9\u306b\u7528\u3044\u3089\u308c\u308b\u65b9\u6cd5\u304c\u6d3b\u7528\u3067\u304d\u307e\u3059\u3002<br \/>\n\u3055\u3066\u3001\u3053\u308c\u306f\u6d3b\u7528\u65b9\u6cd5\u306e1\u4f8b\u3067\u306f\u3042\u308a\u307e\u3059\u304c\u3001\u5f53\u793e\u306e\u793e\u5185\u30b7\u30b9\u30c6\u30e0\u306b\u304a\u3051\u308bDB\u306e\u30c6\u30fc\u30d6\u30eb\u306e\u30ab\u30e9\u30e0\u306b\u306f\u57fa\u672c\u7684\u306b<\/p>\n<ul>\n<li>\u4e3b\u30ad\u30fc(id)<\/li>\n<li>\u30c7\u30fc\u30bf\u306e\u4f5c\u6210\u65e5\u6642<\/li>\n<li>\u30c7\u30fc\u30bf\u306e\u6700\u7d42\u66f4\u65b0\u65e5\u6642<\/li>\n<\/ul>\n<p>\u304c\u3001\u5927\u4f53\u306e\u30c6\u30fc\u30d6\u30eb\u306b\u542b\u307e\u308c\u3066\u3044\u307e\u3059\u3002\u305d\u3057\u3066\u3001\u305d\u306e\u30ab\u30e9\u30e0\u540d\u306f\u3059\u3079\u3066\u3001id,created_at,updated_at\u3068\u306a\u3063\u3066\u3044\u307e\u3059\u3002\u3053\u308c\u3092\u3001\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u306e\u7d99\u627f\u3067\u5b9f\u73fe\u3055\u305b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nuse Doctrine\\ORM\\Mapping as ORM;\r\n\r\n\/**\r\n * @ORM\\MappedSuperclass\r\n * @ORM\\HasLifecycleCallbacks()\r\n *\/\r\nclass UtilEntity{\r\n\r\n    \/**\r\n     * @var bigint $id\r\n     *\r\n     * @ORM\\Column(name=&quot;id&quot;, type=&quot;bigint&quot;, nullable=false)\r\n     * @ORM\\Id\r\n     * @ORM\\GeneratedValue(strategy=&quot;IDENTITY&quot;)\r\n     *\/\r\n    protected $id;\r\n\r\n    \/**\r\n     * @var datetime $createdAt\r\n     *\r\n     * @ORM\\Column(name=&quot;created_at&quot;, type=&quot;datetime&quot;, nullable=false)\r\n     *\/\r\n    protected $createdAt;\r\n\r\n    \/**\r\n     * @var datetime $updatedAt\r\n     *\r\n     * @ORM\\Column(name=&quot;updated_at&quot;, type=&quot;datetime&quot;, nullable=true)\r\n     *\/\r\n    protected $updatedAt;\r\n\r\n    public function __construct($id = null){\r\n        $this-&gt;id = $id;\r\n    }\r\n\r\n    \/**\r\n     * Get id\r\n     *\r\n     * @return bigint\r\n     *\/\r\n    public function getId()\r\n    {\r\n        return $this-&gt;id;\r\n    }\r\n\r\n    \/**\r\n     * Set createdAt\r\n     *\r\n     * @param datetime $createdAt\r\n     *\/\r\n    public function setCreatedAt($createdAt)\r\n    {\r\n        $this-&gt;createdAt = $createdAt;\r\n    }\r\n\r\n    \/**\r\n    * @ORM\\prePersist\r\n    *\/\r\n    public function setCreatedValue()\r\n    {\r\n        $this-&gt;createdAt = new \\DateTime();\r\n    }\r\n\r\n    \/**\r\n     * Get createdAt\r\n     *\r\n     * @return datetime\r\n     *\/\r\n    public function getCreatedAt()\r\n    {\r\n        return $this-&gt;createdAt;\r\n    }\r\n\r\n    \/**\r\n     * Set updatedAt\r\n     *\r\n     * @param datetime $updatedAt\r\n     *\/\r\n    public function setUpdatedAt($updatedAt)\r\n    {\r\n        $this-&gt;updatedAt = $updatedAt;\r\n    }\r\n\r\n    \/**\r\n     * Get updatedAt\r\n     *\r\n     * @return datetime\r\n     *\/\r\n    public function getUpdatedAt()\r\n    {\r\n        return $this-&gt;updatedAt;\r\n    }\r\n\r\n    \/**\r\n    * @ORM\\prePersist\r\n    * @ORM\\preUpdate\r\n    *\/\r\n    public function setUpdatedValue()\r\n    {\r\n        $this-&gt;updatedAt = new \\DateTime();\r\n    }\r\n}\r\n<\/pre>\n<p>\u3068\u3044\u3046\u3001Util\u306a\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u30af\u30e9\u30b9\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002\u30dd\u30a4\u30f3\u30c8\u306f<\/p>\n<ul>\n<li>@Entity\u3092\u4ed8\u4e0e\u3057\u306a\u3044\u3068@ORM\\HasLifecycleCallbacks()\u304c\u306a\u305c\u304b\u8a8d\u8b58\u3057\u3066\u304f\u308c\u306a\u3044<\/li>\n<li>@Entity\u304c\u5b58\u5728\u3059\u308b\u3068\u304d\u3001\u5fc5\u305a@Id\u3092\u4ed8\u4e0e\u3057\u305f\u30d7\u30ed\u30d1\u30c6\u30a3\u304c\uff11\u3064\u306f\u306a\u3044\u3068\u3044\u3051\u306a\u3044<\/li>\n<li>@prepersist(Insert\u6642)\u306b\u73fe\u5728\u306e\u65e5\u6642\u3092created_at\u306b\u633f\u5165\u3059\u308b(setCreatedValue)<\/li>\n<li>@prepersist(Insert\u6642)\u3001@preupdate(Update\u6642)\u306b\u73fe\u5728\u306e\u65e5\u6642\u3092updated_at\u306b\u633f\u5165\u3059\u308b(setUpdatedValue)<\/li>\n<\/ul>\n<p>\u3067\u3059\u3002<br \/>\nDoctrine\u306e\u30a4\u30d9\u30f3\u30c8\u306b\u95a2\u3057\u3066\u306f\u3001<a href=\"http:\/\/docs.symfony.gr.jp\/symfony2\/book\/doctrine.html#lifecycle-callback\" title=\"http:\/\/docs.symfony.gr.jp\/symfony2\/book\/doctrine.html#lifecycle-callback\">http:\/\/docs.symfony.gr.jp\/symfony2\/book\/doctrine.html#lifecycle-callback<\/a>\u3092\u53c2\u8003\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u6700\u5f8c\u306b\u3001\u3053\u306eUtilEntity\u30af\u30e9\u30b9\u3092\u7d99\u627f\u3057\u305f\u3001\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u30af\u30e9\u30b9\u306f\u3001id,created_at,updated_at\u306b\u95a2\u3059\u308b\u8a18\u8ff0\u3092\u304a\u3053\u306a\u3046\u5fc5\u8981\u304c\u306a\u304f\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u3082\u3061\u308d\u3093\u3001\u7d99\u627f\u3057\u305f\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u3092\u4f7f\u3044<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nphp app\/console doctrine:schema:update --force\r\n<\/pre>\n<p>\u3068\u3059\u308c\u3070\u3001\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u304cid,created_at,updated_at\u3092\u6301\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u6b63\u78ba\u306a\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3067\u3057\u3087\u3046\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\u306f\u3001\u4eca\u56de\u306f \u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u30c6\u30fc\u30d6\u30eb\u5b9a\u7fa9\u304b\u3089\u3001\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u3092\u4f5c\u6210\u3059\u308b\u65b9\u6cd5\u3002 \u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u30af\u30e9\u30b9\u3092\u7d99\u627f\u95a2\u4fc2\u3092\u7528\u3044\u3066\u6d3b\u7528\u3059\u308b\u65b9\u6cd5\u3002 \u3092\u89e3\u8aac\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002 \u65e2\u5b58\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092Symfony2\u306b\u79fb\u884c\u3059\u308b\u5834\u5408\u306b\u5f79\u306b&#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-1975","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\/1975","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=1975"}],"version-history":[{"count":4,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts\/1975\/revisions"}],"predecessor-version":[{"id":2000,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts\/1975\/revisions\/2000"}],"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=1975"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/categories?post=1975"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/tags?post=1975"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}