{"id":6224,"date":"2011-10-06T12:07:07","date_gmt":"2011-10-06T03:07:07","guid":{"rendered":"http:\/\/fukata.org\/?p=6224"},"modified":"2017-08-11T22:58:48","modified_gmt":"2017-08-11T22:58:48","slug":"perl-dbix-class-core-straddle-multiple-table-join","status":"publish","type":"post","link":"https:\/\/blog.fukata.org\/archives\/6224\/","title":{"rendered":"DBIx::Class\u3067\u3001\u8907\u6570\u30c6\u30fc\u30d6\u30eb\u3092\u307e\u305f\u3044\u3067join\u3059\u308b"},"content":{"rendered":"
DBIx::Class<\/a>\u3092\u4f7f\u7528\u3057\u3066\u304a\u308a\u3001AR\u306e\u6a5f\u80fd\u3092\u4f7f\u3063\u3066\u3001\u3042\u308b\u30c6\u30fc\u30d6\u30eb\u304b\u3089\u8907\u6570\u30c6\u30fc\u30d6\u30eb\u3092\u307e\u305f\u3044\u3067join\u3059\u308b\u65b9\u6cd5\u3067\u3059\u3002<\/p>\n \u76ee\u6b21<\/p> \u4e0b\u8a18\u306e\u3088\u3046\u306a\u30c6\u30fc\u30d6\u30eb\u69cb\u6210\u3060\u3063\u305f\u3068\u3057\u307e\u3059\u3002<\/p>\n \u3053\u3093\u306a\u611f\u3058\u3067\u7d10\u3065\u3044\u3066\u3044\u307e\u3059\u3002<\/p>\n \u5404\u30e2\u30c7\u30eb\u306b\u306f\u4e0a\u8a18\u306e\u30c7\u30fc\u30bf\u306e\u7d10\u4ed8\u304d\u3092\u4e0b\u8a18\u306e\u3088\u3046\u306b\u8a2d\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n apps<\/strong><\/p>\n users<\/strong><\/p>\n agencies.id\u3067apps\u306e\u4e00\u89a7\u3092\u53d6\u5f97\u3057\u305f\u3044\u3002<\/strong><\/p>\n \u5177\u4f53\u7684\u306a\u30b3\u30fc\u30c9\u306f\u3053\u3093\u306a\u611f\u3058\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n DBIx::Class\u3092\u4f7f\u7528\u3057\u3066\u304a\u308a\u3001AR\u306e\u6a5f\u80fd\u3092\u4f7f\u3063\u3066\u3001\u3042\u308b\u30c6\u30fc\u30d6\u30eb\u304b\u3089\u8907\u6570\u30c6\u30fc\u30d6\u30eb\u3092\u307e\u305f\u3044\u3067join\u3059\u308b\u65b9\u6cd5\u3067\u3059\u3002 \u76ee\u6b211 \u30c6\u30fc\u30d6\u30eb\u69cb\u62101.1 \u30c7\u30fc\u30bf\u9593\u306e\u7d10\u4ed8\u304d2 AR\u306e\u8a2d\u5b9a3 \u3084\u308a\u305f\u3044\u3053\u3068 \u30c6\u30fc … \u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":2,"featured_media":9223372036854775807,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1980],"tags":[911,910],"_links":{"self":[{"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/posts\/6224"}],"collection":[{"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/comments?post=6224"}],"version-history":[{"count":0,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/posts\/6224\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/media\/9223372036854775807"}],"wp:attachment":[{"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/media?parent=6224"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/categories?post=6224"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/tags?post=6224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}\u30c6\u30fc\u30d6\u30eb\u69cb\u6210<\/span><\/h2>\n
\n
\u30c7\u30fc\u30bf\u9593\u306e\u7d10\u4ed8\u304d<\/span><\/h3>\n
\n
AR\u306e\u8a2d\u5b9a<\/span><\/h2>\n
\r\n__PACKAGE__->belongs_to(\r\n user => 'Users',\r\n { 'foreign.id' => 'self.user_id' }\r\n);\r\n<\/pre>\n
\r\n__PACKAGE__->belongs_to(\r\n agency => 'Agencies',\r\n { 'foreign.id' => 'self.agency_id' }\r\n);\r\n<\/pre>\n
\u3084\u308a\u305f\u3044\u3053\u3068<\/span><\/h2>\n
\r\nmy $rs = $apps_model->search( \r\n # conditions\r\n {\r\n 'me.agency_id' => [\u691c\u7d22\u6761\u4ef6\u306e\u5165\u529b\u5024]\r\n },\r\n # attributes\r\n {\r\n join => { user => [qw\/agency\/] }\r\n }\r\n);\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"