posCreate with auto increment column
posCreate with auto increment column

I am using postCreate function to to send data to another table, for example
->on( 'postCreate', function ( $editor, $id, $values ) use ( $db ) {
$db->raw()
->bind( ':e', $values["product_code_fk"] )
->bind( ':f', $values["contract_id"] )
->exec( 'INSERT INTO prodycts_balance (product_code_fk, contract_id_fk)
select :e, :f FROM contracts Where product_code_fk = :e');
})
The issue here is that contract_id
is a primary key with auto increment
values . so as expected it is showing the error contract_id not found. It is because we are not giving the values during create .
Is there a war around for this, for example these values are read from database after they are created and then sent to different table using postCreate?
Thank you
This discussion has been closed.
Answers
Hi,
In
postCreate
(are the server-side) you have a fourth parameter as noted in the docs. That will give you the newly created primary key value. Thevalues
array is what was submitted. The forth parameter ($row
) is what was read back from the database.Allan
Hi @allan
Thank you for the reply. The issue here is , I use two post create
For each created row, it creates 12 rows in same table based on the insert query below
1)
and after this , I want to create a different table using
2)
The isuue is that
$row["contract_id"] ) takes id of first row created.
how can I include the auto increment id's of all rows create dusing first postCreate?Thnak you
If that doesn't work, then you might want to just use the PDO connection directly which is
$db->resource();
.Allan