leftjoin does not update it makes an insert on edit ?
leftjoin does not update it makes an insert on edit ?
Hi,
have two tables.
$out = Editor::inst( $db, 'users','id' )
->fields(
Field::inst( 'users.name' ),
Field::inst( 'users.email' ),
Field::inst( 'forewardings.id' ),
Field::inst( 'forewardings.source')->validator( 'Validate::email')
)
->leftJoin( 'forewardings', 'users.id', '=', 'forewardings.uid' ) ;
$out ->process($_POST);
$out ->data();
$out ->json();
Table looks fine.
Using an editor with 'forewardings.source' an editing, process is making an insert not an update... how can i force update instead insert?
Can i prevent insert/update and use my own SQL-Code?
Thanks.
Alfred
This discussion has been closed.
Replies
Hi,
So on edit, there is always something being INSERTed into the
forewardings
table. Is that correct?I don't quite understand the structure of the data, could you possibly explain what you are trying to do? I don't understand why the
forewardings
table would be edited at all when updating a user.Yes, but you wouldn't be able to use the Editor PHP libraries. You would need to create your own using the Editor client / server communication protocol.
Regards,
Allan
Hi allan,
yes, there is allways a insert.
Well the structure is:
"Usertable" contains the Userdata also an e-mail adress.
"Forewardings has a couple of other adresses which are forewarded to the mail-adress of the user.
eg:
Users
id: 1
User: allan
Mail: foo@faa.com
Forewardings:
id:1
uid:1
source: 1.foo@faa.com
destination:foo@faa.com
id:2
uid:1
source: 2.foo@faa.com
destination:foo@faa.com
In the Table i show:
users.user, forewardings.source, users.Mail
up to here all right.
Now i want to edit just forewardings.source (only one filed in editor).
Pressing the save button there is allways an insert not an update...
Is there no way to prevent sql writing like:
Thanks Alfred
Yes, you can use the
set()
method for a field (docs). Set the option tofalse
and it will prevent Editor writing to the that field.However, there might be something else going on. Are you able to show me your full PHP and Javascript?
Allan
Hi allan,
thanks for the replies.
Well, i already tried the set(false)... maybe i missed the doc ...
is it: $out ->process($_POST) ->set(false); ?
have a look at the sources:
PHP:
Thanks
Alfred
got it..
im on the way for a workaround:
edit: works
new: i got error :
Call to a member function insertId() on a non-object in /....../lib/Editor/Editor.php on line 996
delete: fatal!
no error, but all records in weiter and in mailuser are deleted !
It looks like you have
set( false )
on every field - is that right? In which case no set would ever occur (and possibly why you are getting an error).edit - I think I understand now - simply don't call the
process()
method on the edit action if you want to provide your own SQL update. Call it for the read, delete and insert (assuming you want the default Editor actions for that), but not if you don't want the update.Having said that - there is still something odd going on. It shouldn't do an insert when you are doing an edit unless there is no data matching in the join table.
Allan
Hi allan,
i did a workaround without join. Thanks for the help.
so close it.
Alfred