代码之家  ›  专栏  ›  技术社区  ›  Prody

原则:加入一个表不会将数据标记为已加载

  •  1
  • Prody  · 技术社区  · 16 年前

    所以我有两张桌子:X和Y。

    schema.yml如下所示:

    X: 
      columns:
        something: { type: string(255), notnull: true }
        y_id: { type: integer, notnull: true }
      relations:
        Y: { onDelete: CASCADE, local: y_id, foreign: id, foreignAlias: xs }
    Y:
      columns:
        something: { type: string(255), notnull: true }
    

    在我的表格里我有:

    class XTable extends Doctrine_Table
    {
        function getXesWithYs()
        {
            return $this->createQuery("x")->leftJoin("x.Y y")->execute();
        }
    }
    

    生成的查询实际上同时选择了x.*和y.*,但是当我尝试使用y的数据时,它会对从y中选择的每一行执行额外的查询,其中y.id=x.y\u id。

    所以如果我这么做了:

    echo $results[0]->Y->something;
    

    $result[1] 是的,我得到另一个查询。

    1 回复  |  直到 16 年前
        1
  •  1
  •   johnwards    16 年前

    啊,最愚蠢的或者至少没有很好的记录。

    class XTable extends Doctrine_Table
    {
        function getXesWithYs()
        {
            return $this->createQuery("x")->select('x.*, y.*')->leftJoin("x.Y y")->execute();
        }
    }
    
    推荐文章