Problem - Cactiverecord Model Dose Not Create New Row.

Hi everyone,

I am new in this Yii stuff, and my english is really poor… But i’m working about this two problems ;)

This is my problem:

I want to create a new row in the table "links". I have a CActiveRecord model for this table ("Links").

This is my code:(there are 3 columns in this table: id, a_id and b_id.)




$link = new Links();

$linksAttributes = array(

  'a_id' => $v,

  'b_id' => $this->id);

$link->attributes = $linksAttributes;

if(!$link->save())

  return false;



$v and $this->id are valid values, and this code is part of "afterSave" function in another model.

This code does not work! no rows added to the "links" table…

[The $links->save() returns false]

Someone have an idea why?

Thanks a lot!

My guess is that a_id and b_id are not among the list of valid attributes.

Two comments, btw:

  1. there’s no need to use $link->attributes, you can assign values directly: $link->a_id = $v

  2. ‘return false’ is useless, because you run your code in AFTERsave, not in BEFOREsave.

ok, thanks.

$v was realy not valid value, because a_id must be integer…

so the new code is:




$link = new Links();

$link->peula_id = (int)$v;

$link->marach_id = $this->id;

$link->save();



Now I get "CException": Links has an invalid validation rule. The rule must specify attributes to be validated and the validator name.

What that means?

[size="6"][color="#483D8B"]Problem solved. thanks![/color][/size]

That means something is wrong in "Links" model, in validators definition.