【问题标题】:Doctrine YML schema to represent relationship from multiple columnsDoctrine YML 模式来表示来自多列的关系
【发布时间】:2011-11-15 10:41:29
【问题描述】:

我有以下字段的表格:

father_id child_id

它们都应该指向表“sfGuardUser”。我正在尝试在我的架构文件中定义这种关系,如下所示:

UsersHierarchy:
  tableName:                      users_hierarchy
  columns:
    father_id:                    {type: integer(9), primary: true}
    child_id:                     {type: integer(9), primary: true}
  relations:
    sfGuardUser:
      local:                      father_id
      foreign:                    id
    sfGuardUser:
      local:                      child_id
      foreign:                    id

但结果只有一列与 sfGuardUser 表相关。所以问题是如何让两个列指向 sfGuardUser 表中的同一列?

【问题讨论】:

    标签: symfony1 doctrine schema yaml


    【解决方案1】:

    那是因为每个关系都有相同的名称。试试:

    relations:
        sfGuardUserFather:
          class:                      sfGuardUser
          local:                      father_id
          foreign:                    id
        sfGuardUserChild:
          class:                      sfGuardUser
          local:                      child_id
          foreign:                    id
    

    然后你可以访问你的关系:

    $your_users_hierarchy_obj->sfGuardUserFather;
    $your_users_hierarchy_obj->sfGuardUserChild;
    

    【讨论】:

      猜你喜欢
      • 2018-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多