이 문제에 대한 유용한 정보를 찾았지만 솔루션에 대한 내 머리를 감쌌습니다. 그래서 누군가가 나에게 나는 "오른쪽"방법 할 매우 열심히 노력하고있어 도움이되는 솔루션이 아닌 플러그인/해킹/해결 방법을 설명 할 수 있겠죠 :symfony 1.4 embedRelation 무결성 제약 조건 위반
: 그래서 여기
것은 무엇 내 문제입니다 스키마 :
detect_relations: true
Student:
tableName: student
columns:
id:
type: integer(4)
fixed: false
unsigned: false
primary: true
autoincrement: true
name:
type: string(255)
fixed: false
unsigned: false
primary: false
default: ''
notnull: true
autoincrement: false
parents_id:
type: integer(4)
fixed: false
unsigned: false
primary: false
default: ''
notnull: true
autoincrement: false
relations:
Parents:
refClass: StudentParentLink
local: student_id
foreign: parents_id
onDelete: CASCADE
Parents:
tableName: parents
columns:
id:
type: integer(4)
fixed: false
unsigned: false
primary: true
autoincrement: true
name:
type: string(255)
fixed: false
unsigned: false
primary: false
default: ''
notnull: true
autoincrement: false
email_id:
type: integer(4)
fixed: false
unsigned: false
primary: false
default: '0'
notnull: true
autoincrement: false
relations:
Student:
refClass: StudetParentLink
local: parents_id
forign: student_id
onDelete: CASCADE
Email:
tableName: email
columns:
id:
type: integer(4)
fixed: false
unsigned: false
primary: true
autoincrement: true
email:
type: string(255)
fixed: false
unsigned: false
primary: false
default: ''
notnull: true
autoincrement: false
StudentParentLink:
tableName: student_parent_link
columns:
id:
type: integer(4)
fixed: false
unsigned: false
primary: true
autoincrement: true
student_id:
type: integer(4)
fixed: false
unsigned: false
primary: false
default: '0'
notnull: true
autoincrement: false
parents_id:
type: integer(4)
fixed: false
unsigned: false
primary: false
default: '0'
notnull: true
autoincrement: false
영어로 부모가있는 학생이 있으며 그 부모에게는 이메일 주소가 있습니다. 나는 '
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '2' for key 1
:
이 예상대로보고, 학생의 기록을 추가하기위한 작업//studentForm.class.php
public function configure()
{
if($this->getObject()->isNew() || count($this->getObject()->Parents) == 0)
{
$this->getObject()->Parents[] = new Parents();
}
$parentsSubForm = new sfForm();
$i = 1;
foreach($this->getObject()->Parents as $parents)
{
$parentsForm = new ParentsForm($parents);
$parentSubForm->embedForm("Parent $i",$parentsForm);
$i++;
}
$this->embedForm('Parents',$parentSubForm)
}
그러나 업데이트에 대한 다음과 같은 에러가 발생합니다
그래서 내 학생 양식에서 나는 다음이 무슨 일이 일어나고 있는지 모르겠지만 부모를 위해 업데이트를 삽입하지 않는 것처럼 보이는 것은 설계된 것입니까? 학생 양식을 통해 학부모 이메일 (및이 모든 예제에 나와 있지 않은 모든 데이터 포인트)을 추가/편집 할 수 있어야합니다.
언제나 방향 또는 의견을 환영합니다. 나는 Symfony에 익숙해지고 있으며 이것 같은 작은 뉘앙스는 배울 수있어서 앞으로 나아갈 수 있습니다!
~ 고마워 Zjoia
UPDATE
그래서 나는 여기 절망과 완전히 혼란, 내가 생각하고 찾아 그래 난 멀리 갈 오류를 얻을 수 있어요 수있는 모든 것을 시도했다 하지만 위의 스키마의 모호한 것입니다 이메일은 대일 그래서 사전 양식에 설명 된대로 일을하는 것은 당신이 그것을 관계 할 필요가 작동하지 않는 것입니다 다른 그래서 나는 다음과 같은 코드가 있습니다
if($this->getObject()->isNew() || count($this->getObject()->Email) < 1)
{
$email = new Email($this->getObject()->Email);
$emailForm = new EmailForm($email);
$this->embedForm('Parents Email', $emailForm);
$useFields[] = 'Parents Email';
}else{
$this->embedRelation('Email');
$this->widgetSchema['Email']->setLabel('Parents Email');
$useFields[] = 'Email';
}
이 작품을 그냥 괜찮아. 내가 부모 양식에 있지만 학생 양식 (부모 양식을 포함)에있을 때 부모에게 전자 메일을 다시 연결시키지 않으면 email table
에 전자 메일을 올바르게 작성하지만 parent table
나는 이것을 가지고 화를 낼 것입니다. 이해가 가지 않습니다. 제발 도와주세요!
그는 바보
답변
내가 모델은 그다지 밝혀 제거하는 것 다시 생각 가지고 테이블을 연결했다 오래된 모델을 가지고 밝혀 그 제거 된 모든 미친 이상한 일은 없어졌고, 모든 것이 완벽하게 작동합니다!
항상 뭔가 바보가 놓친
업데이트 정보 확인 ... 아직 도움이 필요합니다. – Zjoia