Can a active record class be created and used in another active record

I have an ar class A has relation has_many with class B

can I creat B instance inside of class A like this:

/**

 * creat B for A


 */


public function addB($attr){


	$b = new B;


	$b->attribute = $attr;


	$b->save();


}

but it seems not working, any ideas? Thanks!

That is possible, and what you’re doing is the general idea. You need to be more specific as to how it seems to be ‘not working’ though. Any errors? Debug info?

I can’t find any errors

I change the function to protected function addB($a, $attr), add it to controller and use it as $this->addB($a, $attr), it works,

but when I add it [public function addB($attr)] in class and invoke it as class function $a->addB($attr) in controller it seems doing nothing and not error or debug info in apache log or application log…