Skip to content

PHP Propel - add a column (with a sub select) to an result

Assuming you want to add a counting column like "numberoffoo" but you want to use your propel environment. Propel, of course, provides a way how you can achive this.

$criteria = new Criteria();
$criteria->addAsColumn(
    'numberoffoo',
    'SELECT
        COUNT()
    FROM
        ' . FooPeer::TABLENAME . '
    WHERE
    ' . FooPeer::BAR
ID . ' = ' . BarPeer::ID . '); )

"Quelle surprise", propel can deal with that also in the cooler query way.
$result = BarQuery::create()->addAsColumn(
    'numberoffoo',
    'SELECT
        COUNT(
)
    FROM
        ' . FooPeer::TABLENAME . '
    WHERE
        ' . FooPeer::BAR
ID . ' = ' . BarPeer::ID . ');
)

source

Translate to de es fr it pt ja