Symfony中的Fixtures和继承

时间:2010-04-19 20:31:04

标签: php symfony1 doctrine symfony-1.4 doctrine-inheritance

我在Symfony中有一个数据库模式,如下所示:

Persona:
    actAs: { Timestampable: ~ }
    columns:
      primer_nombre:  { type: string(255), notnull: true }
      segundo_nombre: { type: string(255) }
      apellido:   { type: string(255), notnull: true }
      rut:         { type: string(255) }
      email:       { type: string(255) }
      email2:      { type: string(255) } 
      direccion:     { type: string(400) }
      ciudad:        { type: string(255) }
      region:      { type: string(255) }
      pais:     { type: string(255) }
      telefono:       { type: string(255) }
      telefono2:      { type: string(255) }
      fecha_nacimiento:   { type: date }

Alumno:
 inheritance:
    type:          concrete
    extends:       Persona
 columns:
  comentario:  { type: string(255) }
  estado_pago: { type: string(255) }

Alumno_Beca:
 columns:
  persona_id:   { type: integer, primary: true }
  beca_id: { type: integer, primary: true }
 relations:
  Alumno: { onDelete: CASCADE, local: persona_id, foreign: id } 
  Beca: { onDelete: CASCADE, local: beca_id, foreign: id } 

Beca:
 columns:
  nombre:        { type: string(255) }
  monto:      { type: double }
  porcentaje:  { type: double }
  descripcion: { type: string(5000) }

如你所见,“alumno”具有“persona”的具体继承。现在我正在尝试为这两个表创建灯具,我不能让Doctrine加载它们。它给了我这个错误:

  

SQLSTATE [23000]:完整性约束   违规:1452无法添加或更新   子行:外键约束   失败(eat/alumno__beca,CONSTRAINT   alumno__beca_persona_id_alumno_id   FOREIGN KEY(persona_id)参考文献   alumnoid)ON DELETE CASCADE)

有人知道如何为从另一个继承的表编写一个fixture吗?

谢谢!

2 个答案:

答案 0 :(得分:1)

我在上周开始使用symfony,今天我遇到了这些问题..

第一个问题是,你的外键必须是整数。 not integer(3)..如果是外键,则不应写入字段大小。而且你的代码也是正确的,这只是一个信息。

第二个问题是, 您应该删除数据库表上的外键索引。如果它已经创建,当你再次插入-sql时会出错。

答案 1 :(得分:0)

我不确定这是否是你唯一的问题,但是当为具有关系的表加载灯具时,按照不违反其外键约束的顺序单独加载它们:第一个父级,然后是子级......不是一切一起。如果您以这种方式定义了关系,则子记录在没有父级的情况下不能“合法地”存在,否则约束将失败。