SELECT

 $c->add(AuthorPeer::NAME, "taro");                      // WHERE name = 'taro' 
 $c->add(AuthorPeer::NAME, "taro", Criteria::NOT_EQUAL); // WHERE name <> 'taro'
 $authors = AuthorPeer::doSelect($c);

Criteriaオペレーター

  • EQUAL (デフォルト)
  • NOT_EQUAL
  • GREATER_THAN
  • LESS_THAN
  • GREATER_EQUAL
  • LESS_EQUAL
  • LIKE
  • NOT_LIKE
  • IN
  • CUSTOM

JOIN

 $c = new Criteria();
 $c->addJoin(ItemPeer::CATETORY_ID, CategoryPeer::ID, Criteria::INNER_JOIN);
 $itemList = ItemPeer::doSelect($c);
 
 // SELECT * FROM item JOIN category ON item.category_id = category.id

LEFT OUTER JOIN 他

 $c->addJoin(ItemPeer::CATETORY_ID, CategoryPeer::ID, 'LEFT OUTER JOIN');

ORDER BY

 $c->addAscendingOrderByColumn(ItemPeer::ID);
 $c->addDescendingOrderByColumn(ItemPeer::ID);

※ 複数カラムによるソートは出来ない。

GROUP BYしてCOUNT()

 SELECT COUNT(category_id) FROM item GROUP BY category_id
 $c->addSelectColumn('COUNT('.ItemPeer::CATEGORY_ID.')');
 $c->addSelectColumn(ItemPeer::CATEGORY_ID);
 $c->addGroupByColumn(ItemPeer::CATEGORY_ID) ;
 $stmt = ItemPeer::doSelectStmt($c);
 $rows = $stmt->fetchAll(PDO::FETCH_NUM);
 foreach ($rows as $r) {
    $count = $r[0];
    $category_id = $r[1];
 }

http://old.nabble.com/How-to-use-aggregate-functions--td18385850.html

カラム名を指定して取得(設定)

 $age = $row->getByName('age');
 $row->setByName('age') = 18;

参考

http://www.propelorm.org/wiki/Documentation/1.5


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