Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use your own SQL do perform a query, but there is no automated way to turn sql into a Criteria object. </p> <pre><code>$con = Propel::getConnection(DATABASE_NAME); $sql = "SELECT books.* FROM books WHERE NOT EXISTS (SELECT id FROM review WHERE book_id = book.id)"; $stmt = $con-&gt;createStatement(); $rs = $stmt-&gt;executeQuery($sql, ResultSet::FETCHMODE_NUM); $books = BookPeer::populateObjects($rs); </code></pre> <p>This bypasses Criterion objects all together. You mentioned wanting a criteria object so you could feed this into a pager. You can instead set a custom select method into your pager, which will then perform your custom query. If you need to pass a parameter into this, I would recommend extending sfPropel with your own pager class that can optionally pass parameters to your peer select methods so you don't have to use Criteria objects at all. As a quick alternative, you can do something like this, using your Criteria as a container for your select parameters:</p> <pre><code>$c = new Criteria(); $c-&gt;add(DiscussreplyPeer::ID, $myId); $pager = new sfPropelPager(); $pager-&gt;setCriteria($c); $pager-&gt;setPeerMethod('getReplies'); </code></pre> <p>And then in your peer class:</p> <pre><code>public static function getReplies(Criteria $c) { $map = $c-&gt;getMap(); $replyId = $map[DiscussreplyPeer::ID]-&gt;getValue(); $con = Propel::getConnection(DATABASE_NAME); $sql = "select p.disrepid, p.subject, p.body, c.disrepid as disrepid1, c.subject as subject1, c.body as body1 from discusreply as p, discusreply as c where p.distopid=? and (c.disrepid = p.parentid or c.parentid = p.distopid) order by p.disrepid ASC"; $stmt = $con-&gt;prepareStatement($sql); $stmt-&gt;setString(1, $replyId); $rs = $stmt-&gt;executeQuery(); $results = array(); while ($rs-&gt;next()) { // for example $results['disrepid'] = $rs-&gt;getInt('disrepid'); } return $results; } </code></pre> <p>More tips on propel and symfony can be found at: <a href="http://stereointeractive.com/blog/2007/06/12/propel-queries-using-custom-sql-peer-classes-and-criterion-objects/" rel="noreferrer">http://stereointeractive.com/blog/2007/06/12/propel-queries-using-custom-sql-peer-classes-and-criterion-objects/</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload