【发布时间】:2011-12-29 20:37:30
【问题描述】:
我有以下型号:
WebPromocion:
connection: doctrine
tableName: WebPromocion
columns:
id:
type: integer(4)
fixed: false
unsigned: true
primary: true
autoincrement: true
nombre:
type: string(100)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
foto:
type: integer(4)
fixed: false
unsigned: true
primary: false
notnull: true
autoincrement: false
flyer:
type: integer(4)
fixed: false
unsigned: true
primary: false
notnull: true
autoincrement: false
desde:
type: timestamp(25)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
hasta:
type: timestamp(25)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
descripcion:
type: string()
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
status:
type: string(1)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
relations:
WebFoto:
local: foto
foreign: id
type: one
WebFoto_2:
class: WebFoto
local: flyer
foreign: id
type: one
WebPromocion_Producto:
local: id
foreign: promocion
type: many
WebFoto:
connection: doctrine
tableName: WebFoto
columns:
id:
type: integer(4)
fixed: false
unsigned: true
primary: true
autoincrement: true
ruta:
type: string(500)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
archivo:
type: string(150)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
nombre:
type: string(255)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
alt:
type: string(255)
fixed: false
unsigned: false
primary: false
default: ''
notnull: true
autoincrement: false
width:
type: integer(4)
fixed: false
unsigned: true
primary: false
notnull: true
autoincrement: false
height:
type: integer(4)
fixed: false
unsigned: true
primary: false
notnull: true
autoincrement: false
map:
type: integer(4)
fixed: false
unsigned: true
primary: false
notnull: false
autoincrement: false
title:
type: string(500)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
thumbnail:
type: string(500)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
relations:
WebFotoMap:
local: map
foreign: id
type: one
WebNoticia:
local: id
foreign: foto
type: many
WebPromocion:
local: id
foreign: foto
type: many
WebPromocion_2:
class: WebPromocion
local: id
foreign: flyer
type: many
如您所见,我的WebPromocion 对象有两个引用WebFoto 对象的字段(“foto”字段和“flyer”字段)。我为WebPromocion 写了一个表单,为WebFoto 嵌入了两个表单,一个叫做'foto',另一个叫做'flyer'....我已经用netbeans 对其进行了调试,它似乎可以很好地构造对象,它保存嵌入对象,但是当它要保存WebPromocion时,sql查询如下:
INSERT INTO WebPromocion (foto, nombre, desde, hasta, descripcion, status,
flyer) VALUES (?, ?, ?, ?, ?, ?, ?) - (5, prueba, 2011-12-29, 2011-12-29,
wepale, A, Array)
在调试时,我发现传递给负责执行的函数的参数是错误的:
exec('INSERT INTO WebPromocion (foto, nombre, desde, hasta, descripcion, status,
flyer) VALUES (?, ?, ?, ?, ?, ?, ?)', array('5', 'prueba', '2011-12-29',
'2011-12-29', 'wepale', 'A', array('nombre' => 'radioactivo', 'alt' =>
'radioactivo', 'width' => 100, 'height' => 100, 'title' => 'help!!!', 'maps' =>
array('map' => array('name' => 'map2', 'areas' => array('area_1' => array(
'shape' => 'rect', 'coords' => '0,0,100,100', 'href' => 'google.com', 'alt'
=> 'google', 'title' => 'google', 'id' => null)), 'id' => null)), 'id' =>
null, 'archivo' => object('sfValidatedFile'))))
所以,对于第一个外键字段('foto'),它放置正确的值(在这种情况下为'5',对应于相关WebFoto的id或主键),但对于第二个一个('传单'),它放置代表WebFoto对象的数组,而不是它的主键......
我不知道该怎么做才能解决这个问题...我尝试使用一个空表单来嵌入WebFotoForms,并将这个嵌入WebPromocionForm,但这样它甚至没有保存WebFoto 对象...我认为这个问题甚至可能是一个建模问题,而不是拥有两个外键('foto' 和'flyer'),我必须有一个多对多的关系...但这只是一个假设,我试图避免改变我的模型...
【问题讨论】:
-
看起来问题是你的关系配置加倍了。我不确定我是否完全经历过您的问题,但我知道它从来没有以这种方式对我有用。尝试仅在一侧定义。
标签: php mysql doctrine symfony-1.4 symfony-forms