views:

25

answers:

2

I'm trying to define conditions on relationships with Doctrine. Is it possible?

I mean something like this:

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?
            ));
    }
}
+2  A: 

As far as I know, such constraints are not possible. Altough I haven't done it myself, I would go with Listeners or Hooks

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

DrColossos
A: 

Another way I have found would be to use model class inheritance:

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

So you would have a ReallySpecialArticle model that extends Article.

mattalexx