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…
'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