Editor - Leftjoin - Does editor create a record in the correspond table?
Editor - Leftjoin - Does editor create a record in the correspond table?
Hi there,
i have short question: `
I'm using Editor to edit records in a table.
The row contains an ID (local_artsid) which refers to a corresponding user table (or is value 0, which means there is no attached 'user' to that row).
Now, i made it possible in the Editor popup to also select a user-value (0) which does not exist in corresponsponding user table (by adding an extra Option, cfr. code below).
Now: whenever I edit a record which does not have a user (value=0) or when i set the value to 0 with the select, a new record is created in the user-table?
Is this normal behaviour and by design? How can I avoid this, because I do not want such an empty row
Field::inst( 'calendar_events.local_artsid' )
->options( ExtOptions::inst()
->pre(array(array("value"=>"","label"=>"Selecteer een arts")))
->pre(array(array("value"=>"0","label"=>"-------")))
->table( 'users' )
->value( 'masterID' )
->label( array('name', 'voornaam') )
->where( function ($q) {
$q->where( 'verwijderd', '0', '=' );
})
->order( 'name asc, voornaam asc' )
->render( function ( $row ) {
return $row['name'].', '.$row['voornaam'];
})
)
I'm using a leftjoin to connect both tables:
->leftJoin('user's,'users.masterID','=', 'calendar_events.local_artsid')
Thanks for any tips,
Filip
This question has an accepted answers - jump to answer
Answers
leftJoin and the options instance are different from each other: within an options instance you can't use a left join for example. Since you didn't post the code for the rest of the Editor instance for which the left join is relevant it is a bit hard to tell. But if you set all the fields of the left joined table to "false" it should stop inserting a record into that table. (This refers to those fields in the rest of the Editor instance that you didn't post, NOT the options instance.)
Take a look at this please:
https://editor.datatables.net/manual/php/getting-started#SQL-functions
Thank you so much for your answer, rf1234!!
This solved it! I wasn't aware of this behaviour!
And indeed, i used three fields referring to the User table (not in the options, but in the table itself i used the left join), and putting them all on false (->set( false )) solved the mistery! No more creation of empty records!
You save me a lot of headaches and time! Thnx.
Note: this issue forced me to finally upgrade to the most recent versions of datatables en editor as well. So not all time was wasted, after all :-)
Kind regards,
Filip
Glad you got it sorted!
I still have to do that today