Save() calls delete and update


#1

Hi guys … why would cakephp delete his own entries on method save() called? I started logging queries since every update my entries were gone.

Querylog:

2017-07-05 13:24:47 Debug: duration=0 rows=0 SELECT ChannelProgramModerations.channel_program_id AS     `ChannelProgramModerations__channel_program_id`, ChannelProgramModerations.date_create AS `ChannelProgramModerations__date_create`, ChannelProgramModerations.date_change AS `ChannelProgramModerations__date_change` FROM channel_program_moderations ChannelProgramModerations WHERE channel_program_id = 23
2017-07-05 13:24:47 Debug: duration=0 rows=1 DELETE FROM channel_program_dows WHERE channel_program_id = 23
2017-07-05 13:24:47 Debug: duration=0 rows=0 DELETE FROM channel_program_genres WHERE channel_program_id = 23
2017-07-05 13:24:47 Debug: duration=0 rows=0 DELETE FROM channel_program_styles WHERE channel_program_id = 23
2017-07-05 13:24:47 Debug: duration=0 rows=0 DELETE FROM channel_program_track_loops WHERE channel_program_id = 23
2017-07-05 13:24:47 Debug: duration=0 rows=0 DELETE FROM channel_program_valid_ranges WHERE channel_program_id = 23
2017-07-05 13:24:47 Debug: duration=0 rows=1 DELETE FROM channel_programs WHERE id = 23
2017-07-05 13:24:47 Debug: duration=0 rows=0 UPDATE channel_programs SET time_start = '07:20:00' , time_end = '07:30:00' , all_day = 0 , date_change = '2017-07-05 13:24:47' WHERE id = 23
2017-07-05 13:24:47 Debug: duration=0 rows=0 UPDATE channel_program_specials SET date_change = '2017-07-05 13:24:47' WHERE channel_program_id = 23
2017-07-05 13:24:47 Debug: duration=0 rows=0 COMMIT

Corresponding model

src\Controller\ChannelProgramSpecialsController.php (line 468)

object(App\Model\Entity\ChannelProgram) {

'id' => (int) 23,
'channel_id' => (int) 1,
'time_start' => object(Cake\I18n\FrozenTime) {

	'time' => '1970-01-01T07:20:00+01:00',
	'timezone' => 'Europe/Vienna',
	'fixedNowTime' => false

},
'time_end' => object(Cake\I18n\FrozenTime) {

	'time' => '1970-01-01T07:30:00+01:00',
	'timezone' => 'Europe/Vienna',
	'fixedNowTime' => false

},
'all_day' => false,
'date_create' => object(Cake\I18n\FrozenTime) {

	'time' => '2017-07-05T11:53:06+00:00',
	'timezone' => 'UTC',
	'fixedNowTime' => false

},
'date_change' => object(Cake\I18n\FrozenTime) {

	'time' => '2017-07-05T11:53:06+00:00',
	'timezone' => 'UTC',
	'fixedNowTime' => false

},
'program_type' => 'event',
'program_interval_type' => 'weekly',
'channel_program_valid_range' => [
	'valid_from' => '',
	'valid_to' => ''
],
'channel_program_dow' => object(App\Model\Entity\ChannelProgramDow) {

	'channel_program_id' => (int) 23,
	'day' => 'monday',
	'date_create' => object(Cake\I18n\FrozenTime) {

		'time' => '2017-07-05T11:53:06+00:00',
		'timezone' => 'UTC',
		'fixedNowTime' => false
	
	},
	'date_change' => object(Cake\I18n\FrozenTime) {

		'time' => '2017-07-05T11:53:06+00:00',
		'timezone' => 'UTC',
		'fixedNowTime' => false
	
	},
	'[new]' => false,
	'[accessible]' => [
		'*' => true
	],
	'[dirty]' => [],
	'[original]' => [],
	'[virtual]' => [],
	'[errors]' => [],
	'[invalid]' => [],
	'[repository]' => 'ChannelProgramDows'

},
'channel_program_special' => object(App\Model\Entity\ChannelProgramSpecial) {

	'channel_program_id' => (int) 23,
	'date_create' => object(Cake\I18n\FrozenTime) {

		'time' => '2017-07-05T11:53:06+00:00',
		'timezone' => 'UTC',
		'fixedNowTime' => false
	
	},
	'date_change' => object(Cake\I18n\FrozenTime) {

		'time' => '2017-07-05T11:53:06+00:00',
		'timezone' => 'UTC',
		'fixedNowTime' => false
	
	},
	'channel_program_special_blocks' => [
		(int) 0 => object(App\Model\Entity\ChannelProgramSpecialBlock) {

			'special_id' => (int) 1,
			'id' => (int) 23,
			'date_create' => object(Cake\I18n\FrozenTime) {

				'time' => '2017-07-05T11:53:06+00:00',
				'timezone' => 'UTC',
				'fixedNowTime' => false
			
			},
			'date_change' => object(Cake\I18n\FrozenTime) {

				'time' => '2017-07-05T11:53:06+00:00',
				'timezone' => 'UTC',
				'fixedNowTime' => false
			
			},
			'[new]' => false,
			'[accessible]' => [
				'*' => true
			],
			'[dirty]' => [],
			'[original]' => [],
			'[virtual]' => [],
			'[errors]' => [],
			'[invalid]' => [],
			'[repository]' => 'ChannelProgramSpecialBlocks'
		
		}
	],
	'[new]' => false,
	'[accessible]' => [
		'*' => true
	],
	'[dirty]' => [],
	'[original]' => [],
	'[virtual]' => [],
	'[errors]' => [],
	'[invalid]' => [],
	'[repository]' => 'ChannelProgramSpecials'

},
'range_type' => 'weekly',
'weekly' => [
	'monday' => 'on'
],
'[new]' => false,
'[accessible]' => [
	'*' => true
],
'[dirty]' => [
	'channel_program_special' => true,
	'time_start' => true,
	'time_end' => true,
	'range_type' => true,
	'weekly' => true,
	'channel_program_valid_range' => true
],
'[original]' => [
	'time_start' => object(Cake\I18n\FrozenTime) {

		'time' => '2017-07-05T07:20:00+00:00',
		'timezone' => 'UTC',
		'fixedNowTime' => false
	
	},
	'time_end' => object(Cake\I18n\FrozenTime) {

		'time' => '2017-07-05T07:25:00+00:00',
		'timezone' => 'UTC',
		'fixedNowTime' => false
	
	},
	'channel_program_valid_range' => null
],
'[virtual]' => [],
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'ChannelPrograms'

}

This does not make sense to me … first deleting and afterwards updating those entries?!
I am just editing two fields inside - seriously some other fields also get marked as dirty … ID fields of associated models are also present, therefore there is no reason for deleting?

Any idea?

regards,


#2

It seems to me, that deletions are from other tables than updates.
Maybe place your code here (action responding for this save).


#3

save() will delete rows when updating hasMany or belongsToMany relationships.


#4

Thanks for your answers so far. I figured out (shame on me) that i have an beforeSave() method, that checks for interactions between those programs (if there is an interaction, it will delete this entry).

problem solved now!

thanks!