4

I'd like know if there are a way to create my own rules to AR relationships or extends the existent HAS_MANY, BELONGS_TO etc?

Thanks.

Stephan Muller
  • 27,018
  • 16
  • 85
  • 126
GodFather
  • 3,031
  • 4
  • 25
  • 36
  • 1
    Can you clearly specify an example of such a custom relationship? – Jon Mar 19 '11 at 00:32
  • Here you can find usefull information about CActiveRelation http://www.yiiframework.com/doc/api/1.1/CActiveRelation – ArtoAle Mar 19 '11 at 13:50

1 Answers1

0

Each AR relationships is created with the corresponding class.

    const BELONGS_TO='CBelongsToRelation';
    const HAS_ONE='CHasOneRelation';
    const HAS_MANY='CHasManyRelation';
    const MANY_MANY='CManyManyRelation';
    const STAT='CStatRelation';

These classes extend CActiveRelation » CBaseActiveRelation » CComponent.

You may be able to create your own AR relationship with a custom class extending CActiveRelation.

Mathieu Lordon
  • 287
  • 1
  • 7
  • following your line of reasoning, I have 2 questions: 1 - can I create my own relationship class called – for exemple – polymorhic? 2 - where can I store my custom relation classes? – GodFather Mar 01 '11 at 14:45
  • I never did that but I think you can. Look what CActiveRelation do and how relation classes extend it to know what your class must do. I didn't find any documentation about it. You can store your custom relation classes anywhere but be sure Yii knows where it is. – Mathieu Lordon Mar 02 '11 at 08:38