Yii:如何访问带有限制的相关模型对象

I've two model class like A, B

A and B both has relation defined in model class like:

class A extends CActiveRecord {
  ...
  public function relations() {
    return array(
      'b' => array(self::HAS_MANY, 'B', 'a_id'),
    );
  }
  ...
}

class B extends CActiveRecord {
  ...
  public function relations() {
    return array(
      'a' => array(self::BELONGS_TO, 'A', 'a_id'),
    );
  }
  ...
}

Now I'm fetching all A using script:

$a = A::model()->findAll();

Then after I'm accessing all A's related object of B, but I want only limited records, like just 4 B's for each A's:

foreach($a as $each_a) {
  $b = $each_a->b; // Want only 4 B's here
}

How can I access only 4 B's records for each A's

change 
$bList = $a->b(array('limit',4));
to  
 $bList = $a->b(array('limit'=>4));

You can pass a size parameter to the getter function.

Try the following:

$bList = $a->b(array('limit',4));

This should return 4 records. You can also add additional things like order to identify which 4 to get.