SELECT - DBIx::Class::ResultSet

SEARCH

 $rs = $c->model('DB::User')->search({address => 'tokyo'},{order_by => ['name', 'id']})
 $rs = $c->model('DB::User')->search({age => {'>=' => 20})
 $rs = $c->model('DB::User')->search({hobby => undef) # SQL:"hobby is null"

IN

 $c->model('DB::User')->search({user_id => {-in => \@user_ids}})

JOIN (2つのテーブルと)

 SELECT order.* FROM order JOIN order_detail ON order.id = order_detail.order_id 
 JOIN goods order_detail.goods_id = goods.id 
 WHERE goods.name = 'book'
 
 $rs = $c->model('DB::Order')->search({
  "goods.name" => 'book',
 },{ 
   join => {order_detail => 'goods'}
 });

PREFETCH

 $rs = $rs->search(undef,{prefetch => 'user', join => 'user'});

ジョインするテーブルをjoin=>'TABLE名'で明示する事。


トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS