Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
[MySQL] DB Joins - Error
  • So before fuel 1.4 - 1.5 (I'm not sure the exact version that broke this) I was able to join fields like this ..

            ->join(array('photos', 'd'), 'LEFT OUTER')
            ->on('a.user_id', '=', 'd.user_id')
            ->on('d.main', '=', 1)

    Now .. fuel gives me an error on the last line of code .. that 1 isn't a valid field. That's weird .. because this is actually working MYSQL syntax, and saves me a where clause on the join.

    Please advise.


  • HarroHarro
    Accepted Answer
    You have never been able to pass literals. It expects a field name there, and will escape it for security reasons, which means 1 will become `1`, which fails.

    You have to encapsulate it in a DB::expr(), to avoid it being escaped:

            ->join(array('photos', 'd'), 'LEFT OUTER')
            ->on('a.user_id', '=', 'd.user_id')
            ->on('d.main', '=', DB::expr(1))
  • Thank you sir.

Howdy, Stranger!

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

In this Discussion