inner join instead of leftJoin function
inner join instead of leftJoin function
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.
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
I assume you're talking about Laravel and Yajra DataTables. How about using join()?
See more articles about jQuery DataTables on gyrocode.com.
Sorry @gyrocode I edited my question. I'm not using Laravel
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.
It's hard-coded because it's in the "_perform_left_join ()" method.
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