Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Inner join
  • Hi I can't figure out how to do and inner joint
    seems that the "related" function uses a left join by default Thx
    Chris
  • Can't be changed. It's indeed a left join while I thought we had changed that to inner joins a long time ago, don't have a clue why we changed it back tbh.
  • ouch! Any ideas to make it work?
    I'm trying to get all the users that received an email ( email is the table that I'm joining with )
    Because it's a left join, it returns all the users...
  • It actually wouldn't be that hard to add support for it, there's already an array passed for where & order_by conditions. Allowing a join_type key in there wouldn't be much trouble. Change for example this line: https://github.com/fuel/orm/blob/1.0/master/classes/hasone.php#L59 to:
    'join_type' => array_key_exists('join_type', $conditions) ? $conditions['join_type'] : 'left',
    

    (same for other relation types) And you can do this:
    Model_Example::query()->related('something', array('join_type' => 'inner'))->get();
    

    If you don't feel up to this try checking if the PK column of the joined table is null, that'll also get rid of the empty rows.
  • Wow. thanks a lot Jelmer! Works like a charm!
  • I've updated the repo to include this.

Howdy, Stranger!

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

In this Discussion