Create And Save 1000 Model Instance At Once

Hi I’m new to Yii&PHP

1)whensystem user create a Record in model A (table tbl_A) it and after $model->save(); I need to create a 1000 or more

record of Model B (table tbl_B)

now I’m calling a function from Acontroller

//////////////////////////////////////////

actionCreate(){

$a->save();

$this->gen_bs($count ,$aid);}

////////////////////////////////////////////

function gen_bs($count ,$aid){

for (i=0; i<$count ;i++){

$b= new B ;

$b->value=100;

$b->Aid = $aid ;

$b->save();

}}

is this good idea or should I do something else

2)each record in B must have a unique& unpredictable code

is there is any thing in Yii that helps me with that

thanks

/* moved to General Discussion */

(not related to a Yii Extension)

you can do it by triggers in database.

On the other hand, you should do it in a beforeSave() method of the model.