Search code examples
phpormpropel

Reusing Propel query bug or my bad?


Simple Propel reusing query is not working here, despite my code is similar to the example on Propel website. Is this a bug or my bad?

$q = MashupSettingQuery::create()->filterByMashup($this);
var_dump($q->count(), $q->findOneByKey('redirect_uri'), $q->count());

Output is:

int 5

object(MashupSetting)[28]
  protected 'startCopy' => boolean false
  protected 'id' => int 9
  protected 'key' => string 'redirect_uri' (length=12)

int 1

that is, resusing is not working because count() first returns 5 and then 1.

Even using MashupSettingQuery::create()->filterByMashup($this)->keepQuery(true) didn't fix the problem.


Solution

  • I think it's normal because just before the second count you make a findOneByKey query, and so the second count just count how many objects this specific query return. And your query return just one object, obviously because it's a findOneByKey.