【问题标题】:Doctrine 1.2: Defining conditions on relationships教义 1.2:定义关系的条件
【发布时间】:2010-09-11 16:30:02
【问题描述】:

我正在尝试定义与 Doctrine 关系的条件。是否可以?

我的意思是这样的:

class User extends Doctrine_Record
{
    public function setUp()
    {
        $this->hasMany('Article as ReallySpecialArticles', array(
            'local' => 'id',
            'foreign' => 'user_id',
            'conditions' => 'Article.really_special <> 0' // What should this be?
            ));
    }
}

【问题讨论】:

    标签: model doctrine doctrine-1.2


    【解决方案1】:

    据我所知,这样的限制是不可能的。虽然我自己没有做过,但我会选择 Listeners 或 Hooks

    http://www.doctrine-project.org/projects/orm/1.2/docs/manual/event-listeners/pl#record-hooks

    【讨论】:

      【解决方案2】:

      我发现的另一种方法是使用模型类继承:

      http://www.doctrine-project.org/projects/orm/1.2/docs/manual/inheritance/en#column-aggregation

      因此,您将拥有一个扩展 Article 的 RealSpecialArticle 模型。

      【讨论】:

        猜你喜欢
        • 2012-03-26
        • 1970-01-01
        • 2011-04-08
        • 1970-01-01
        • 1970-01-01
        • 2018-08-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多