2011-08-09 30 views
0

私の非常に稀なケースでは、同じテーブルで2対多の関係を作成する必要があります。 私は説明します: 私は2つのテーブルを持っています。 MonitorとServerは、多くの場合、中間のテーブルを「ベンチマーク」と呼びます。しかし同時に、別の中間テーブルを用意する必要があります。このテーブルを使用すると、モニターのURLをサーバーの複数のIPに結合できます(テーブルは「Url_ip」と呼ばれます)。 これは私が行ったことです。Doctrine/symfony:SAMEの2つのテーブルで2対多の関係(2つの中間テーブル)を作成する

実際には、doctrineは対応するテーブルを作成できるので、これは機能するようです。 問題は、フィックスを読み込むときです。私はこのエラーがあります:

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` 
)) 

fixures/monitors.yml

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 

HELP alerts.yml

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 

fixures/benchmark.yml

Monitor: 
    monitor_one: 
    id: 1 
    label: task1 
    url: www.task1.com 
    frequency: 5 
    timeout: 30 
    method: GET 
    parameters: a=1&b=2 

    monitor_two: 
    id: 2 
    label: task2 
    url: www.task2.com 
    frequency: 5 
    timeout: 20 
    method: POST 
    parameters: a=11&b=22 

    monitor_three: 
    id: 3 
    label: task3 
    url: www.task3.com 
    frequency: 10 
    timeout: 30 
    method: GET 
    parameters: a=111&b=211 

fixures/- --------> SOS

答えて

0

Alertモデルの外観はどうなっていますか? (それはUrl_ipですか?)

IDの代わりにキーでモデルを参照する方が良いです。

Monitor: 
    monitor1: 
    .... 

Alert: 
    alert_a: 
    Monitor: monitor1 
    Group: group1 

エラーはあなたが今取得しているので、あなたが存在しないモニターを参照してAlertを追加することを意味します。これはMonitorの前にAlertが挿入されたときに発生します。 idの代わりにMonitorをキーで参照することで、symfonyはMonitorを最初に挿入します。

+0

質問を修正し、アラート構造を追加しました。 alert_a: モニター:monitor_one グループ:それを – ProXamer

+0

をお読みください私は、このやったGroup_admin – ProXamer

+0

をしかし、私はこのエラーがあります: クラスでいう「(警告)alert_a」を「グループ」と「sfGuard グループ」であることが予想されました – ProXamer

0

これは、私は小さなトリックを見つけた!実際にモニターで 、私は言ったようでした:キーを使用! しかし、グループiでは正常に処理されましたが、sfGuardのIDを使用していました。

Alert: 
    alert_a: 
    Monitor: monitor1 
    sf_guard_group: group1 
関連する問題