Many After Many

Hi

i got 2 tables:

TABLE A

=======

ID

A_ID

TABLE B

=======

ID

A_ID

a object of type A can have a parent of type A and it can have multiple children of type A.

and each object of type A can have multiple children of type B.

i have a object of type A wiht no parent, so it is the root,

and i want to get the number of objects of type B connected to itself and all its children.

All the way up the tree.

It’s more a Database problem than yii. You need to have one to many relationship to a third table where you put an id as primary key, a parent_id and a child_id poiting both to the id of your object A table. Then in your model, when you’ll create it by gii, you will have a relations in function as SELF::HAS_MANY in it… start by that, but I encourage you to read some wiki…

http://www.yiiframework.com/doc/guide/1.1/en/database.arr for example

I did not see type B to itself depends on your table definition.

Is that the hierarchy structure in an organization?

got it


'As' => array(self::HAS_MANY, 'A', 'root'),//all the A's connected to the root, root points to the root of the tree in Table A.

'Bs'=> array( self::HAS_MANY, 'B', array('ID'=>'A_ID'), 'through'=>'As' ),//all the Bs connected to all As