left join two fields

left join two fields

ManuelWennerManuelWenner Posts: 16Questions: 2Answers: 1

Hey together,

is it possible to execute a left join with two fields like the following?
leftJoin( 'sites', 'sites.id', '=', 'users.site' ) AND
leftJoin( 'sites', 'sites.id2', '=', 'users.id2' )

Thanks in advance

Answers

  • allanallan Posts: 61,740Questions: 1Answers: 10,111 Site admin

    Hi,

    Unfortunately no, not at this time, sorry. The best you can currently do is:

      ->leftJoin( 'sites', 'sites.id', '=', 'users.site' )
      ->where( 'sites.id', 'users.id2' )
    

    Regards,
    Allan

  • ManuelWennerManuelWenner Posts: 16Questions: 2Answers: 1

    Hey Allan,

    thanks for your quick reply. So is it possible to do another query in the getFormatter function of a field? Something like:

    Field::inst( 'price' )->getFormatter(function ( $val, $data, $opts ) {            
               //TODO: query 
    }),
    
  • ManuelWennerManuelWenner Posts: 16Questions: 2Answers: 1

    Hey Allan,

    i found a solution. Now i am using "$db->query('select')" inside the ->getFormatter function. That works great for me.
    Keep on rockin. DataTables is awesome!

    Greetings
    Manuel

  • allanallan Posts: 61,740Questions: 1Answers: 10,111 Site admin

    Hi Manuel,

    Good to hear that works! One thing you should be aware of is that the query in getFormatter will be executed for every row in the table. Okay for small data sets, but not so good for large ones!

    Allan

  • lissacoffeylissacoffey Posts: 3Questions: 0Answers: 0

    So is it possible to do another query in the getFormatter function of a field?

  • allanallan Posts: 61,740Questions: 1Answers: 10,111 Site admin

    Yes absolutely. As I noted above it does have the downside of being executed once for every row, so you need to be careful about using it.

    Allan

  • ManuelWennerManuelWenner Posts: 16Questions: 2Answers: 1

    @lissacoffey
    Like mentioned above all you have to do (in my case) is inside getFormatter function

    global $db;
    $result = $db->query("select")
                ->table( "tableName")
                ->get( 'columnName' )
                ->where('', '')
                ->exec();        
                  
                $value = $result->fetch()['value']; 
    
This discussion has been closed.