".. must be an integer" & checkBoxList

Hey there.

I have three tables:

I am trying to insert a new post I have checkBoxList where I can check categories that belongs to post.

These are validaton rules for post2category:

When I click on submit I get an error that IDcategory must be an integer.

Also, I just want to use these validates when trying to insert a new row. For an example, it cannot be possible to insert IDcategory without IDpost. It’s allowed both or none.

Help?

Since post2category is a linking table, you don’t expect user input for it, and that is why you should remove the rules for it. Rules are only for user input. You should create the linking relation / model manually, when a user has entered data in your post and category form.

Handling mutliple models in one form is a favorite topic in Yii. There are many extensions that try to make saving, updating etc. easier.

Here is a wiki article to get you started: http://www.yiiframework.com/wiki/19/how-to-use-a-single-form-to-collect-data-for-two-or-more-models/

There are also many extensions. For example with-related-behavior, advancedrelationsbehavior, activerecord-relation-behavior and esaverelatedbehavior.

Thanks you. :)