Note that there are some explanatory texts on larger screens.

plurals
  1. PODoctrine/symfony : creating 2 many-to-many relations(2 intermediate tables) on the SAME two tables
    text
    copied!<p>in my very "rare" case, i must create 2 many-to-many relations on the same tables. I explain: I have a two tables ; Monitor and Server having many to many rel the intermediate table will be called "Benchmark". But in the same time i have to have another intermediate table which can allow me to couple a url from a monitor to several ip's from the servers (the table is called "Url_ip") So here is what i've done :</p> <pre><code> Monitor: tableName: monitor actAs: Timestampable: ~ columns: id : {type: integer(4), primary: true, autoincrement: true} 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: Groups: class: Groups local: monitor_id foreign: sf_guard_group_id refClass: Alert Server: class: Server local: monitor_id foreign: server_id refClass: Benchmark Server2: class: Server local: monitor_id foreign: server_id foreignAlias: Ips refClass: Url_ip Url_ip: actAs: Timestampable: ~ columns: monitor_id: { type: integer(4), primary: true } server_id: { type: integer(4), primary: true } relations: Monitor: foreignAlias: IpUrls Server: foreignAlias: IpUrls Benchmark: tableName: benchmark actAs: Timestampable: ~ columns: monitor_id: { type: integer(4), primary: true } server_id: { type: integer(4), primary: true } connexionTime: {type: string(45)} executionTime: {type: string(45)} responseTime: {type: string(45)} responseCode: {type: string(45)} responseMessage: {type: string(45)} relations: Monitor: foreignAlias: ServerMonitors Server: foreignAlias: ServerMonitors Server: tableName: server actAs: TimeStampable: ~ columns: id : {type: integer(4), primary: true,autoincrement: true} name: {type: string(255)} ip: {type: string(45)} relations: Monitor: class: Monitor local: server_id foreign: monitor_id refClass: Benchmark Monitor2: class: Monitor foreignAlias: monitors local: server_id foreign: monitor_id refClass: Url_ip Alert: actAs: Timestampable: ~ columns: monitor_id: { type: integer(4), primary: true } sf_guard_group_id: { type: integer, primary: true } relations: Monitor: foreignAlias: GroupMonitors sfGuardGroup: foreignAlias: GroupMonitors </code></pre> <p>Actually this appears to work because doctrine can create corresponding tables. The problem is when loading the fixures. i have this error:</p> <pre><code> SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a c hild row: a foreign key constraint fails (`sfmonitoring`.`alert`, CONSTRAINT `al ert_monitor_id_monitor_id` FOREIGN KEY (`monitor_id`) REFERENCES `monitor` (`id` )) </code></pre> <p>fixures/monitors.yml</p> <pre><code>Monitor: monitor_one: id: 1 label: task1 url: www.task1.com frequency: 5 timeout: 30 method: GET parameters: a=1&amp;b=2 monitor_two: id: 2 label: task2 url: www.task2.com frequency: 5 timeout: 20 method: POST parameters: a=11&amp;b=22 monitor_three: id: 3 label: task3 url: www.task3.com frequency: 10 timeout: 30 method: GET parameters: a=111&amp;b=211 </code></pre> <p>fixures/benchmark.yml</p> <pre><code>Benchmark: bench_one: monitor_id: 1 server_id: 1 connexionTime: 25 executionTime: 25 responseTime: 25 responseCode: 200 responseMessage: message de réponse bench_two: monitor_id: 2 server_id: 2 connexionTime: 25 executionTime: 25 responseTime: 25 responseCode: 200 responseMessage: message de réponse bench_three: monitor_id: 3 server_id: 3 connexionTime: 25 executionTime: 25 responseTime: 25 responseCode: 200 responseMessage: message de réponse bench_Four: monitor_id: 1 server_id: 2 connexionTime: 25 executionTime: 25 responseTime: 25 responseCode: 200 responseMessage: message de réponse </code></pre> <p>fixures/alerts.yml</p> <pre><code>Alert: alert_a: monitor_id: 1 sf_guard_group_id: 1 alert_b: monitor_id: 2 sf_guard_group_id: 2Alert: alert_a: monitor_id: 1 sf_guard_group_id: 1 alert_b: monitor_id: 2 sf_guard_group_id: 2 </code></pre> <p>HELP ---------> S.O.S</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload