Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
How to create EXISTS or NOT EXISTS statements?
  • Hi, I'd like to be able to create a IF NOT EXISTS subquery, however the where() method always expects a column to be given, so something like Model_Xyz::find()
    ->where(null, 'not exists', DB::query(SELECT * FROM foo))
    ->get() will always generate WHERE `t0`.`` NOT EXISTS (SELECT * FROM `foo`), which of course is invalid SQL. If only there was a way to allow where() to not require a column... What would be the best thing to do here? Extend the Orm query model and write my own where_exists() function or similar? Thanks!
  • Try
    DB::expr('not exists')
    
  • Oh that works perfectly, thanks!
  • paulbennett wrote on Tuesday 7th of February 2012:
    Oh that works perfectly, thanks!

    What did your final query look like? I'm trying to do the same thing, but I can't figure out where to put my DB::expr(). Thanks.
  • You can use DB::expr() for everything that you don't want to be escaped.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion