Updating block gives insert errors
Permalink
Hi,
I am trying to create a custom block which works a bit similar to the image slider and that is why I took that as my boilerplate. I have the following structure for things.
1) The main Table is the FullScreenScroll which currently stores nothing but will store the options in the future.
2) The FullScreenScrollSection table which stores the different full page section
3) The FullScreenScrollSlide table which stores the individual slides of a section.
Following is my save code.
It works fine when creating a new block. But when I publish it and then edit the block again I get the following error:
I do not understand what am I doing wrong compared to that of the image slider as the code is structured in the same format. Any help would be really appreciated.
Thank you,
Shivaraman Aiyer
I am trying to create a custom block which works a bit similar to the image slider and that is why I took that as my boilerplate. I have the following structure for things.
1) The main Table is the FullScreenScroll which currently stores nothing but will store the options in the future.
2) The FullScreenScrollSection table which stores the different full page section
3) The FullScreenScrollSlide table which stores the individual slides of a section.
Following is my save code.
public function save($args){ // var_dump($args); $db = Database::get(); $db->delete('btFullScreenScroll', array('bID' => $this->bID)); $db->query('DELETE from btFullScreenScroll WHERE bID=?', array($this->bID)); $db->query('DELETE from btFullScreenScrollSection WHERE bID = ?', array($this->bID)); $db->query('DELETE from btFullScreenScrollSlide WHERE bID = ?', array($this->bID)); $args['bID'] = $this->bID; // parent::save($args); if (isset($args['sectionSortOrder'])) { $sectionCount = count($args['sectionSortOrder']); for ($i=0;$i < $sectionCount;$i++) { $db->execute('INSERT INTO btFullScreenScrollSection (bID,section_sort_order) values(?, ?)', array( $this->bID,
Viewing 15 lines of 41 lines. View entire code block.
It works fine when creating a new block. But when I publish it and then edit the block again I get the following error:
An exception occurred while executing 'INSERT INTO btFullScreenScroll (bID) VALUES (?)' with params ["227"]: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '0' for key 'PRIMARY'
I do not understand what am I doing wrong compared to that of the image slider as the code is structured in the same format. Any help would be really appreciated.
Thank you,
Shivaraman Aiyer