Symfony1 Symfony 1.4/doctrine schema.yml多对多关系不';你不能正常工作吗?
我这里有个小麻烦! 使用symfony 1.4和条令! 事实上,我有一个“多对多”关系(见下面的代码),但我没有正确的结果Symfony1 Symfony 1.4/doctrine schema.yml多对多关系不';你不能正常工作吗?,symfony1,doctrine,symfony-1.4,doctrine-1.2,Symfony1,Doctrine,Symfony 1.4,Doctrine 1.2,我这里有个小麻烦! 使用symfony 1.4和条令! 事实上,我有一个“多对多”关系(见下面的代码),但我没有正确的结果 Monitor: actAs: Timestampable: ~ columns: label: {type: string(45)} url: {type: string(80)} frequency: {type: integer} timeout: {type: integer} method: {ty
Monitor:
actAs:
Timestampable: ~
columns:
label: {type: string(45)}
url: {type: string(80)}
frequency: {type: integer}
timeout: {type: integer}
method: {type: enum, values: [GET, POST]}
parameters: {type: string(255)}
relations:
Server:
foreignAlias: Servers
refClass: Benchmark
local: monitor_id
foreign: server_id
Server:
actAs:
Timestampable: ~
columns:
name: string(255)
ip: string(255)
relations:
Monitor:
foreignAlias: Monitors
refClass: Benchmark
local: server_id
foreign: monitor_id
Benchmark:
actAs:
Timestampable: ~
columns:
monitor_id: { type: integer, primary: true }
server_id: { type: integer, primary: true }
connexionTime: {type: string(45)}
executionTime: {type: string(45)}
responseTime: {type: string(45)}
responseCode: {type: string(45)}
responseMessage: {type: string(45)}
relations:
Monitor:
local: monitor_id
foreign: id
foreignAlias: Monitors
Server:
local: server_id
foreign: id
foreignAlias: Servers
1-在添加服务器(或监视器)界面中,会出现一个监视器(或服务器)列表(但我可以添加服务器(或监视器),而无需选择它)
2-在添加基准界面中,我没有监视器和服务器列表来选择它们!提交时我不工作(无论如何都不应该!)。我收到以下错误:
500 | Internal Server Error | Doctrine_Connection_Mysql_Exception
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`sfmonitoring`.`benchmark`, CONSTRAINT `benchmark_monitor_id_monitor_id` FOREIGN KEY (`monitor_id`) REFERENCES `monitor` (`id`))
我在BaseBenchmarkForm类中有这段代码
abstract class BaseBenchmarkForm extends BaseFormDoctrine
{
public function setup()
{
$this->setWidgets(array(
'monitor_id' => new sfWidgetFormInputHidden(),
'server_id' => new sfWidgetFormInputHidden(),
'connexionTime' => new sfWidgetFormInputText(),
'executionTime' => new sfWidgetFormInputText(),
'responseTime' => new sfWidgetFormInputText(),
'responseCode' => new sfWidgetFormInputText(),
'responseMessage' => new sfWidgetFormInputText(),
'created_at' => new sfWidgetFormDateTime(),
'updated_at' => new sfWidgetFormDateTime(),
));
$this->setValidators(array(
'monitor_id' => new sfValidatorChoice(array('choices' => array($this->getObject()->get('monitor_id')), 'empty_value' => $this->getObject()->get('monitor_id'), 'required' => false)),
'server_id' => new sfValidatorChoice(array('choices' => array($this->getObject()->get('server_id')), 'empty_value' => $this->getObject()->get('server_id'), 'required' => false)),
'connexionTime' => new sfValidatorString(array('max_length' => 45, 'required' => false)),
'executionTime' => new sfValidatorString(array('max_length' => 45, 'required' => false)),
有什么想法吗,伙计们??????
我真的被挡住了
###############################################V2
谢谢你的帮助,这对我来说真的很重要!
我做了这些转变:
Monitor:
tableName: monitor
actAs:
Timestampable: ~
columns:
label: {type: string(45)}
url: {type: string(80)}
frequency: {type: integer}
timeout: {type: integer}
method: {type: enum, values: [GET, POST]}
parameters: {type: string(255)}
Benchmark:
actAs:
Timestampable: ~
columns:
monitor_id: { type: integer, primary: true }
server_id: { type: integer, primary: true }
connexionTime: {type: string(45)}
executionTime: {type: string(45)}
responseTime: {type: string(45)}
responseCode: {type: string(45)}
responseMessage: {type: string(45)}
relations:
Monitor: { onDelete: CASCADE, local: monitor_id, foreign: id, foreignAlias: Monitors }
Server: { onDelete: CASCADE, local: server_id, foreign: id, foreignAlias: Servers }
Server:
actAs:
Timestampable: ~
columns:
name: string(255)
ip: string(255)
但是在基准的“新建”界面中,我仍然没有得到服务器和监视器列表!您在
Server
关系中的refClass
定义只能指向一个具有两个字段的模型:每个拥有方一个字段(在本例中,Server
和Monitor
)。通过以这种方式创建多对多关系,您可以调用$server->Monitors
,并自动使用此refClass
创建监视器
(而不是基准
)的集合(作为用户,您看不到refClass)
如果您想在这个“耦合类”基准中拥有更多数据,就像您所做的那样,您必须使用来分离关系
只需在服务器中删除关系,您可能就完成了。好的,有两个:获取的(SQL)错误意味着您要保存的基准测试具有无效的监视器id
。因此它要么是空的,要么是指不存在的监视器
这可能是因为您没有选择监视器/服务器,因为它们在表单上不可见(它们呈现为sfWidgetFormInputHidden
)。
要显示这两个的
s,您必须转到基准表单
(它覆盖基本基准表单
,并覆盖configure()
方法。类似如下:
public function configure() {
parent::configure();
$this->widgetSchema['monitor_id'] = sfWidgetFormDoctrineChoice(array('model' => 'Monitor'));
$this->widgetSchema['server_id'] = sfWidgetFormDoctrineChoice(array('model' => 'Server'));
$this->validatorSchema['monitor_id'] = sfValidatorDoctrineChoice(array('model' => 'Monitor'));
$this->validatorSchema['server_id'] = sfValidatorDoctrineChoice(array('model' => 'Server'));
}
我修改了我的问题,请阅读,我在基准新界面上没有得到正确的结果!请阅读我修改的问题,因为我仍然无法重播mes自己的问题!提交基准时,它表示监视器和服务器字段中的值无效。您还需要更新验证程序。请参阅我的更新版本代码示例::-(如果有效,请不要忘记接受我的答案;-)如果是!请注意,我还有另一个同样的问题,但是SfGuardGroup表在多对多关系中使用!我会在几分钟内发布!