inner join instead of leftJoin function

inner join instead of leftJoin function

mishkemishke Posts: 3Questions: 1Answers: 0
edited August 2017 in Free community support

Is it possible to join tables with inner instead of left join? I was using leftJoin() function but I don't get the right result from the database, so I need to use inner join. How can I accomplish this?

I'm using this code right now, but is there a function or something to use inner join instead of this leftJoin function.

Look at this example

Editor::inst( $db, 'address', 'address_id' )
->fields(
Field::inst( 'address.address' )->validator( 'Validate::notEmpty' ),
Field::inst( 'address.city' )->validator( 'Validate::notEmpty' ),
Field::inst( 'address.postal_code' )->validator( 'Validate::notEmpty' ),
Field::inst( 'address.country' )->validator( 'Validate::notEmpty' ),
Field::inst( 'address.phone' )->validator( 'Validate::notEmpty' ),
Field::inst('orders.total')->validator("Validate::notEmpty"),
Field::inst('orders.paid')->validator("Validate::notEmpty")
)
->leftJoin('orders', 'orders.address_id', '=', 'address.address_id')
->process( $_POST )
->json();

Answers

  • gyrocodegyrocode Posts: 126Questions: 6Answers: 30

    I assume you're talking about Laravel and Yajra DataTables. How about using join()?


    See more articles about jQuery DataTables on gyrocode.com.

  • mishkemishke Posts: 3Questions: 1Answers: 0

    Sorry @gyrocode I edited my question. I'm not using Laravel

  • mishkemishke Posts: 3Questions: 1Answers: 0
    edited August 2017

    Ok, I looked at the source code and I found hard-coded 'LEFT' in Editor.php file, line 1576

    $query->join( $join['table'], $join['field1'].' '.$join['operator'].' '.$join['field2'], 'LEFT' );
    in _perform_left_join function

    And I changed left to inner, and I think it works now. I don't know why is that hard-coded, or maybe I'm wrong I don't know.

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    It's hard-coded because it's in the "_perform_left_join ()" method.

  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin

    The Editor PHP libraries haven't been tested for use with a LEFT INNER JOIN (they use LEFT JOIN / LEFT OUTER JOIN since that is the most common use case). However, I don't foresee any issues with using an inner join there.

    Allan

This discussion has been closed.