Association error?


#1

Hello!

I am trying to save a three level association:

ChannelProgram hasOne (1:1) ChannelProgramSpecials hasMany (1:n) ChannelProgramSpecialBlocks

The same association build with other tables works like a charm:

ChannelProgram hasOne (1:1) ChannelProgramSpots hasMany (1:n) ChannelProgramSpotBlocks

The code of saving the first is quite similar to the working second.

Error output when saving:

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`bradio_one`.`channel_program_special_blocks`, CONSTRAINT `FK_PROGRAM_SPECIAL_BLOCKS` FOREIGN KEY (`channel_program_special_id`) REFERENCES `channel_program_specials` (`channel_program_id`) ON)

Entity structure before save method called:

object(App\Model\Entity\ChannelProgram) {

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

	'channel_program_special_blocks' => [
		(int) 0 => object(App\Model\Entity\ChannelProgramSpecialBlock) {

			'special_id' => (int) 1,
			'date_change' => object(Cake\I18n\Time) {

				'time' => '2017-05-09T08:25:29+02:00',
				'timezone' => 'Europe/Vienna',
				'fixedNowTime' => false
			
			},
			'date_create' => object(Cake\I18n\Time) {

				'time' => '2017-05-09T08:25:29+02:00',
				'timezone' => 'Europe/Vienna',
				'fixedNowTime' => false
			
			},
			'[new]' => true,
			'[accessible]' => [
				'*' => true
			],
			'[dirty]' => [
				'special_id' => true,
				'date_change' => true,
				'date_create' => true
			],
			'[original]' => [],
			'[virtual]' => [],
			'[errors]' => [],
			'[invalid]' => [],
			'[repository]' => 'ChannelProgramSpecialBlocks'
		
		},
		(int) 1 => object(App\Model\Entity\ChannelProgramSpecialBlock) {

			'special_id' => (int) 2,
			'date_change' => object(Cake\I18n\Time) {

				'time' => '2017-05-09T08:25:29+02:00',
				'timezone' => 'Europe/Vienna',
				'fixedNowTime' => false
			
			},
			'date_create' => object(Cake\I18n\Time) {

				'time' => '2017-05-09T08:25:29+02:00',
				'timezone' => 'Europe/Vienna',
				'fixedNowTime' => false
			
			},
			'[new]' => true,
			'[accessible]' => [
				'*' => true
			],
			'[dirty]' => [
				'special_id' => true,
				'date_change' => true,
				'date_create' => true
			],
			'[original]' => [],
			'[virtual]' => [],
			'[errors]' => [],
			'[invalid]' => [],
			'[repository]' => 'ChannelProgramSpecialBlocks'
		
		}
	],
	'date_change' => object(Cake\I18n\Time) {

		'time' => '2017-05-09T08:25:29+02:00',
		'timezone' => 'Europe/Vienna',
		'fixedNowTime' => false
	
	},
	'date_create' => object(Cake\I18n\Time) {

		'time' => '2017-05-09T08:25:29+02:00',
		'timezone' => 'Europe/Vienna',
		'fixedNowTime' => false
	
	},
	'[new]' => true,
	'[accessible]' => [
		'*' => true
	],
	'[dirty]' => [
		'channel_program_special_blocks' => true,
		'date_change' => true,
		'date_create' => true
	],
	'[original]' => [],
	'[virtual]' => [],
	'[errors]' => [],
	'[invalid]' => [],
	'[repository]' => 'ChannelProgramSpecials'

},
'interval_type' => 'once',
'once_time' => '02:00',
'interval_minute' => '',
'interval_from' => '',
'interval_to' => '',
'range_type' => 'weekly',
'weekly' => [
	'monday' => 'on'
],
'channel_program_valid_range' => [
	'valid_from' => '',
	'valid_to' => ''
],
'channel_id' => (int) 14,
'time_start' => object(Cake\I18n\Time) {

	'time' => '2017-05-09T02:00:00+02:00',
	'timezone' => 'Europe/Vienna',
	'fixedNowTime' => false

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

	'time' => '2017-05-09T02:10:00+02:00',
	'timezone' => 'Europe/Vienna',
	'fixedNowTime' => false

},
'channel_program_dow' => object(App\Model\Entity\ChannelProgramDow) {

	'day' => 'monday',
	'date_change' => object(Cake\I18n\Time) {

		'time' => '2017-05-09T08:25:29+02:00',
		'timezone' => 'Europe/Vienna',
		'fixedNowTime' => false
	
	},
	'date_create' => object(Cake\I18n\Time) {

		'time' => '2017-05-09T08:25:29+02:00',
		'timezone' => 'Europe/Vienna',
		'fixedNowTime' => false
	
	},
	'[new]' => true,
	'[accessible]' => [
		'*' => true
	],
	'[dirty]' => [
		'day' => true,
		'date_change' => true,
		'date_create' => true
	],
	'[original]' => [],
	'[virtual]' => [],
	'[errors]' => [],
	'[invalid]' => [],
	'[repository]' => 'ChannelProgramDows'

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

	'time' => '2017-05-09T08:25:29+02:00',
	'timezone' => 'Europe/Vienna',
	'fixedNowTime' => false

},
'date_create' => object(Cake\I18n\Time) {

	'time' => '2017-05-09T08:25:29+02:00',
	'timezone' => 'Europe/Vienna',
	'fixedNowTime' => false

},
'[new]' => true,
'[accessible]' => [
	'*' => true
],
'[dirty]' => [
	'channel_program_special' => true,
	'interval_type' => true,
	'once_time' => true,
	'interval_minute' => true,
	'interval_from' => true,
	'interval_to' => true,
	'range_type' => true,
	'weekly' => true,
	'channel_program_valid_range' => true,
	'channel_id' => true,
	'time_start' => true,
	'time_end' => true,
	'channel_program_dow' => true,
	'date_change' => true,
	'date_create' => true
],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'ChannelPrograms'

}

In comparison the working entity (second one):

object(App\Model\Entity\ChannelProgram) {

'channel_program_spot' => object(App\Model\Entity\ChannelProgramSpot) {

	'channel_program_spot_blocks' => [
		(int) 0 => object(App\Model\Entity\ChannelProgramSpotBlock) {

			'spot_id' => (int) 2,
			'date_change' => object(Cake\I18n\Time) {

				'time' => '2017-05-09T08:26:28+02:00',
				'timezone' => 'Europe/Vienna',
				'fixedNowTime' => false
			
			},
			'date_create' => object(Cake\I18n\Time) {

				'time' => '2017-05-09T08:26:28+02:00',
				'timezone' => 'Europe/Vienna',
				'fixedNowTime' => false
			
			},
			'[new]' => true,
			'[accessible]' => [
				'*' => true
			],
			'[dirty]' => [
				'spot_id' => true,
				'date_change' => true,
				'date_create' => true
			],
			'[original]' => [],
			'[virtual]' => [],
			'[errors]' => [],
			'[invalid]' => [],
			'[repository]' => 'ChannelProgramSpotBlocks'
		
		},
		(int) 1 => object(App\Model\Entity\ChannelProgramSpotBlock) {

			'spot_id' => (int) 1,
			'date_change' => object(Cake\I18n\Time) {

				'time' => '2017-05-09T08:26:28+02:00',
				'timezone' => 'Europe/Vienna',
				'fixedNowTime' => false
			
			},
			'date_create' => object(Cake\I18n\Time) {

				'time' => '2017-05-09T08:26:28+02:00',
				'timezone' => 'Europe/Vienna',
				'fixedNowTime' => false
			
			},
			'[new]' => true,
			'[accessible]' => [
				'*' => true
			],
			'[dirty]' => [
				'spot_id' => true,
				'date_change' => true,
				'date_create' => true
			],
			'[original]' => [],
			'[virtual]' => [],
			'[errors]' => [],
			'[invalid]' => [],
			'[repository]' => 'ChannelProgramSpotBlocks'
		
		}
	],
	'date_change' => object(Cake\I18n\Time) {

		'time' => '2017-05-09T08:26:29+02:00',
		'timezone' => 'Europe/Vienna',
		'fixedNowTime' => false
	
	},
	'date_create' => object(Cake\I18n\Time) {

		'time' => '2017-05-09T08:26:29+02:00',
		'timezone' => 'Europe/Vienna',
		'fixedNowTime' => false
	
	},
	'[new]' => true,
	'[accessible]' => [
		'*' => true
	],
	'[dirty]' => [
		'channel_program_spot_blocks' => true,
		'date_change' => true,
		'date_create' => true
	],
	'[original]' => [],
	'[virtual]' => [],
	'[errors]' => [],
	'[invalid]' => [],
	'[repository]' => 'ChannelProgramSpots'

},
'interval_type' => 'once',
'once_time' => '00:15',
'interval_minute' => '',
'interval_from' => '',
'interval_to' => '',
'range_type' => 'weekly',
'weekly' => [
	'wednesday' => 'on',
	'thursday' => 'on'
],
'channel_program_valid_range' => [
	'valid_from' => '',
	'valid_to' => ''
],
'channel_id' => (int) 14,
'time_start' => object(Cake\I18n\Time) {

	'time' => '2017-05-09T00:15:00+02:00',
	'timezone' => 'Europe/Vienna',
	'fixedNowTime' => false

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

	'time' => '2017-05-09T00:25:00+02:00',
	'timezone' => 'Europe/Vienna',
	'fixedNowTime' => false

},
'channel_program_dow' => object(App\Model\Entity\ChannelProgramDow) {

	'day' => 'wednesday',
	'date_change' => object(Cake\I18n\Time) {

		'time' => '2017-05-09T08:26:29+02:00',
		'timezone' => 'Europe/Vienna',
		'fixedNowTime' => false
	
	},
	'date_create' => object(Cake\I18n\Time) {

		'time' => '2017-05-09T08:26:29+02:00',
		'timezone' => 'Europe/Vienna',
		'fixedNowTime' => false
	
	},
	'[new]' => true,
	'[accessible]' => [
		'*' => true
	],
	'[dirty]' => [
		'day' => true,
		'date_change' => true,
		'date_create' => true
	],
	'[original]' => [],
	'[virtual]' => [],
	'[errors]' => [],
	'[invalid]' => [],
	'[repository]' => 'ChannelProgramDows'

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

	'time' => '2017-05-09T08:26:29+02:00',
	'timezone' => 'Europe/Vienna',
	'fixedNowTime' => false

},
'date_create' => object(Cake\I18n\Time) {

	'time' => '2017-05-09T08:26:29+02:00',
	'timezone' => 'Europe/Vienna',
	'fixedNowTime' => false

},
'[new]' => true,
'[accessible]' => [
	'*' => true
],
'[dirty]' => [
	'channel_program_spot' => true,
	'interval_type' => true,
	'once_time' => true,
	'interval_minute' => true,
	'interval_from' => true,
	'interval_to' => true,
	'range_type' => true,
	'weekly' => true,
	'channel_program_valid_range' => true,
	'channel_id' => true,
	'time_start' => true,
	'time_end' => true,
	'channel_program_dow' => true,
	'date_change' => true,
	'date_create' => true
],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'ChannelPrograms'

}

I am stucked here and would appreciate your help!

Kind regards,

Andre


#2

I have also tried to insert the same with a third one (same table association like the two above) - this one works also …

Any suppositions?


#3

Can you please post the table definition for the Entity that does not work? In my experience there is any non-null value specified on the table that is not explicitly set in your entity…


#4

Already solved, thanks for your suggestion!