AR save() method error

Greetings to all.

Yii is my first framework, i’ve started to study it two weeks ago.

And recently i’ve faced the problem, that I can’t solve.

Let us assume that there is a MySQL table table with the composite index id_1, id_2 and the third field value. And there is an AR-model Table.

I have to change value field of the record with given index through AJAX. I don’t use integrated AJAX-handlers and develop my own with JQuery.

So, the function, that changes the value, looks like:


// i find the desired record

        $model = Table::model()->findByAttributes(array(

            'id_1' => $id_1,

            'id_2' => $id_2,

        ));

// change it's value

        $model->value = 'VALUE';

// save it and print the result

        if($model->save()) {

            exit('1');

        }

        else {

            exit('0');

        }

Before saving the value there is no problems. Also, i’ve tried to launch


$model->validate();

and there were no problems with it.

But when this method starts:


$model->save();

the Exception

throws.

And I do not understand, what’s the problem. May be I’m too tired to think brightly, but, really, what’s going on?

Could anybody explain me?

PS: Creating of new records of this model is fine (without AJAX), and other models are good too. I suppose that AJAX making it impossible to save the record, but it’s just an intuition, not a strong explanation.

Thanks for help ahead of time,

and excuse my English.

Enable profiling on your database connection and enable debug mode, usually you can tell from the generated SQL query what’s going wrong.

Also be careful when using reserved words as names for your tables or column (such as naming your Model ‘Table’ and your column ‘value’. This may sometimes lead to syntax errors in your generated SQL. I’m not saying that’s happening here, just a thought :)

It was just an example:) Anyway, thanks.

After some hours of healthy sleep I’ve fixed this problem in 10 minutes :) I created composite index of two fields, but i did not make it Primary. So Yii couldn’t save this record, because it couldn’t find correct index.

No patch for human stupidity. And don’t work day and night :)