Hi all!
I was starting to work with some HABTM relations and I've found the
following problem: Whenever I try to save the relationship between the
models I'm using (subject,teacher) more than one time, cake creates
duplicate entries into the subjects_teachers table.
I've created an unike key so it wouldn`t do that. It works but I got
some mySQL errors:
SQL Error: 1062: Duplicate entry '1-1' for key 'unique link' [CORE\cake
\libs\model\datasources\dbo_source.php, line 525]
Code | Context
$sql = "INSERT INTO `subjects_teachers` (`subject_id`,`teacher_id`)
VALUES (1,1)"
$error = "1062: Duplicate entry '1-1' for key 'unique link'"
$out = null
---
I didn`t use unique key set to true because I handle independent
associations every time.
---
The controller code is the following:
function assignTeacher()
{
$this->Subject->recursive = -1;
$subjects = $this->Subject->find('all');
foreach ($subjects as $data)
{
$this->Subject->Teacher->recursive = -1;
$teachers = $this->Subject->Teacher->find('all',
array('conditions'
=> array('Teacher.subjects LIKE' => '%'.$data['Subject']
['code'].'%')));
foreach ($teachers as $teacher_data)
{
$data['Teacher']['id'] =
$teacher_data['Teacher']['id'];
$this->Subject->save($data);
}
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---