I have a little disturbing problem in here!
an using symfony 1.4 with Doctrine!
i fact i have a “many to many” relation (see code bellow) but i don’t have the RIGHT result!
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- when in the add server (or monitor) interface there is a list of monitors (or servers) that appears (but i can add a server(or monitor) without selecting it.
2- when in the add benchmark interface, i don’t have the monitors and servers list in order to select them! and when i submit i doesn’t work (it should’nt any way!). i get this error:
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`))
i have this code in the BaseBenchmarkForm class
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)),
ANY IDEAS GUYS ??????
Pleaaaaaase am really Blocked !
############################################### V2
Thank you for the Help, it really means to me!
I did theses transformations:
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)
But in the benchmark “new” interface, i still don’t get the servers and the monitors list!
Okay, take two: The (SQL) error your getting means that the
Benchmarkyou want to save, has an invalidmonitor_id. So it’s either empty or refers to a non-existing monitor.This probably happens because you didn’t select a monitor/server, because they were invisible on the form (they are rendered as
sfWidgetFormInputHidden).To show the
<select>s for these two, you have to go to theBenchmarkForm(which overrides theBaseBenchmarkForm, and override theconfigure()method. Something like this: