Model Save Not Working, No Errors, No Validation

Hey, I’m trying to save a model (via insert), but it’s not working. Here’s my save code:




$rulecompete = new UserRuleCompetitorsPerRule();


$rulecompete->competitor_id = intval($val); // this is a foreign ID

$rulecompete->rule_set_id = intval($userRuleSett_model->id); // another foreign ID


$rulecompete->save(false);



I’ve debugged for a while:

[list=1]

[*]save returns true

[*]i’ve checked and it even validates properly

[*]->getErrors is empty

[/list]

But still the data just DOESN’T save to the database.

The weirder thing is, that it DID save before. It only recently stopped working.

Any idea what’s going on? How I can debug this further? application.log is empty.

Thanks!

Remove the false to trigger validation:

[size="2"]


$rulecompete->save();

[/size]

Matt

Like I mentioned, I’ve already tried validating and it still runs properly (except it simply doesn’t save to the database)

Thanks,

Chen

What about beforeSave or afterValidation functions? Have you overridden any of these or attached relevant events?

Nope, this is probably the simplest model in the house. No custom functions, heck not even a controller. Just basic model with save/load.

Can we have a peek at your table schema?


CREATE TABLE `user_rule_competitors_per_rule` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `rule_set_id` int(11) NOT NULL,

  `competitor_id` int(11) NOT NULL,

  PRIMARY KEY (`id`)

) ENGINE=InnoDB AUTO_INCREMENT=107 DEFAULT CHARSET=latin1


	public function rules()

	{

		// NOTE: you should only define rules for those attributes that

		// will receive user inputs.

		return array(

			array('rule_set_id, competitor_id', 'required'),

			array('rule_set_id, competitor_id', 'numerical', 'integerOnly'=>true),

			// The following rule is used by search().

			// Please remove those attributes that should not be searched.

			array('id, rule_set_id, competitor_id', 'safe'),

		);

	}

Do you have xdebug set up? Just step into save() function and see what’s going on.

Test the connection database, do you have another database on your system?


$test = Yii::app()->db->createCommand('select * from user_rule_competitors_per_rule')->queryAll();


var_dump ($test);

If the data not matching with your database data then you use another database

the other actions works properly?

Check also if the


Yii::app()->db->createCommand('insert into from user_rule_competitors_per_rule (rule_set_id, competitor_id) VALUES (1,1))->execute(); 

write in your database

I am having the exact same problem. I thought I was going crazy. I tried the suggestion above and it worked perfectly. I still don’t know why the save isn’t working. I’m going to try to get debug going and see what I can find out there.

Please post both of you the whole generated Model AR and database table schema, also which database and version you use?