Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
DB join on with a value problem
  • Hi I want to create a query like this:

    $user_id = 5;
    $query = \DB::select('companies.*', \DB::expr('IF(test.user_id,"YES","NO") AS connected'))
                ->from('companies')
                ->join('test', 'LEFT')
                ->on('test.company_id', '=', 'companies.id')
                ->on('test.user_id', '=', $user_id)
                ->order_by('connected', 'DESC')
                ->order_by('companies.count_blogs', 'DESC')
                ->as_object()
                ->execute();

    But this gives a problem with this line:
    ->on('test.user_id', '=', $user_id)

    I want the join to look like this: LEFT JOIN test ON (test.company_id=companies.id AND test.user_id=5)

    it seems it cannot bind a variable to a join, only columns...
  • created an issue on github for it: https://github.com/fuel/core/issues/1768
  • it seems this works:

    ->on('test.user_id', '=', \DB::expr($user_id))

Howdy, Stranger!

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

In this Discussion