Symfony1 条令/符号:在相同的两个表上创建2个多对多关系(2个中间表)

Symfony1 条令/符号:在相同的两个表上创建2个多对多关系(2个中间表),symfony1,doctrine,symfony-1.4,doctrine-1.2,Symfony1,Doctrine,Symfony 1.4,Doctrine 1.2,在我非常“罕见”的情况下,我必须在同一个表上创建2个多对多关系。 我解释: 我有两张桌子;监视器和服务器具有多对多rel,中间表将被称为“基准”。但同时,我必须有另一个中间表,它允许我将一个监视器的url与服务器的多个ip连接起来(该表称为“url_ip”) 以下是我所做的: Monitor: tableName: monitor actAs: Timestampable: ~ columns: id : {type:

在我非常“罕见”的情况下,我必须在同一个表上创建2个多对多关系。 我解释: 我有两张桌子;监视器和服务器具有多对多rel,中间表将被称为“基准”。但同时,我必须有另一个中间表,它允许我将一个监视器的url与服务器的多个ip连接起来(该表称为“url_ip”) 以下是我所做的:

    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
实际上,这似乎是可行的,因为条令可以创建相应的表。 问题在于加载固定件时。我有一个错误:

  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`
))
Fixers/monitors.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
fixes/benchmark.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/alerts.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

帮助-------------->S.O.S

您的
Alert
型号是什么样子?(这是
Url\u ip
?)

最好通过模型的键而不是ID来引用模型

Monitor:
  monitor1:
    ....

Alert:
  alert_a:
    Monitor: monitor1
    Group: group1

因为您现在遇到的错误意味着您添加了一个
警报
,其中引用了一个不存在的监视器。当在
监视器
之前插入
警报
时,可能会发生这种情况。通过按键而不是id引用
监视器
,symfony将首先插入
监视器。

就是这样,我发现了一个小把戏! 事实上在班长,我确实像你说的:用了钥匙! 但在小组中,我正常处理,但使用的是sfGuard的id,而不是我的

Alert:
  alert_a:
    Monitor: monitor1
    sf_guard_group: group1

我修改了我的问题并添加了警报结构。请阅读iti所做的操作:警报\u a:Monitor:Monitor\u one组:组\u Admin但我有一个错误:“(警报)警报\u a”中引用的类应为“组”,并且“sfGuard组”被赋予我使用sfGuard自己的装置