Form validation to database

Hi!, I want to do this in a Yii way, but I don’t know how…

I have a table “Ingredients” with “Id_ingredient, name, id_user”. All users can add a new ingredient with a form. But there are a common ingredients like oil, salt, bread, egg, etc…wich has id_user=0. Users can add a new ingredients if there aren’t in the list of common ingredients (id_user=0).

Wich is the best way to do this? validate on model? controller?

Sorry for my english and thanks!

Create a custom validator in the model.

http://www.yiiframework.com/wiki/168/create-your-own-validation-rule/

The CExistValidator takes additional criteria. Just tell the validator that only ingredients with a user_id<>0 are acceptable and you should be good to go B)

Thanks, but Can I do a query to another table from a model?

thanks, I take a look!