can't save data in database (update the other model)

Hi everyone,

I have the codes below in another php file(not questions controller)


$questions=Questions::model()->findByAttributes(array('id'=>$event->commentedModel->id));

$questions->reply_time=date( 'Y-m-d H:i:s', time() );

$questions->save();

I thought it will update the specific question’s reply_time, but it actually not.

I tried print getError() but it can’t even display the error…

Any ideas about why…?

Thanks!!

Hi,

maybe you can check that reply_time is safe in your model, rr try to var_dump your date-time value.

Uhmmm…I thought it was the problem but I add ‘safe’ in my model…

still, can’t save the value in the database…I could save my date in question controller but not in this way…

The problem is the "…->save()"

If I comment this line, then no error happens although apparently no data will be saved…

You can check these:

[list=1]

[*]Does your $questions really get the model you’re fetching?

[*]What are your model relations? Does the model behind commentedModel relation have

[*]Is id the PK for your table or a foreign key?

[*]What are your rules for Questions model? Are they met when you set only reply_time?

[*]Have you tried skipping validation with [font=“Courier New”]$questions->save(false);[/font] or saving only the wanted attribute with [font=“Courier New”]$questions-> saveAttributes(array(‘reply_time’));[/font]?

[/list]