Search code examples
phpcomboboxpropel

Filtering Propel collection


I'm trying do a linked combo between Country/State via Ajax. The change combo events is ok. But i need help with the filtering via Propel.

// provincia == state ; pais == country :)
// $provincias contains only one "provincia". Because i have only one state in the       country.
$provincias = ProvinciasQuery::create()->filterByIdpais($_GET['pais']);

$data = array();

foreach($provincias as $provincia) {
$data[] = Array('id' => $provincia->getIdprovincia(), 'name' => $provincia->getProvincia())
}

This code fails with the next error:

[20-Nov-2012 16:10:23 UTC] PHP Fatal error: Call to undefined method Criterion::getIdprovincia()

Any idea ? Thanks !.


Solution

  • When you use filter from query, you have to call find() at the end. Now in $provincias you have Criteria object, not the query result.

    $provincias = ProvinciasQuery::create()->filterByIdpais($_GET['pais'])->find();