Search code examples
symfony1propel

Is there any way to output the sql generated by a propel select in symfony?


I want to output the query generated by a symfony propel select for testing purposes. Is there any way to do this? I know I can use the sf_debug bar, but sometimes I need to see the statement in a situation where the sf_debug bar hasn't loaded yet, or isn't going to load at all.


Solution

  • Timmow is right that there is a Criteria::toString() method, but it's not the magic _toString() method that's automatically called when the object is referenced as a string.

    If you want to see the SQL you have to explicitly call Criteria::toString().

    $c = new Criteria();
    // HERE: add criteria
    // what's it do?
    echo $c->toString(); // oh, that's what it does