【问题标题】:find all child tables (dependencies flowing inward) using doctrine使用学说查找所有子表(向内流动的依赖项)
【发布时间】:2011-10-27 23:52:21
【问题描述】:

所以如果我有一个模型 Student,它是 Tests 和 Homework 的参考,有没有办法使用返回 Tests 和 Homework 的 Student 的 Model 或 Table 类?本质上,我想手动执行“删除级联”,而不必知道需要删除的表——我希望从 Doctrine 的一种方法中获取这些表。

【问题讨论】:

    标签: symfony1 doctrine


    【解决方案1】:

    你可以得到一个类的所有关系:

    $relations = Doctrine_Core::getTable('<CLASS_NAME>')->getRelations();
    
    foreach($relations as $relation)
      echo $relation->getClass();
    

    请参阅Doctrine_Relation_AssociationDoctrine_Relation 了解更多信息。

    【讨论】:

      【解决方案2】:

      你也可以使用:

      $relations = Doctrine_Core::getTable('Student')->findAll();
      
      foreach($relations as $relation)
        echo $relation->getTests();
      

      【讨论】:

      • 这样你得到的是对象,而不是关系。
      猜你喜欢
      • 2015-12-25
      • 1970-01-01
      • 1970-01-01
      • 2010-09-16
      • 1970-01-01
      • 2014-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多