Check multiple cakephp selection

I am using CakePHP and I have something like:

PRODUCT -------> PRODUCT_CATEGORY <---------- CATEGORY

therefore, one product may have categories of "n" and vice versa. The problem is that I would like to check products to have at least one category. Since I use a form helper, and CakePHP y validation functions came to this:

class Product extends AppModel {
    var $name = 'Product';
    var $validate = array(
        'category_id' => array(
            'rule' => array('multiple', array('min' => 1)),
            'message' => 'You have to choose at least one category'
        )
    );
}

But it doesn’t work, any ideas?

+3
source share
2 answers

I think you should not check the category_id category, use the category (the name of your model) instead.

, ablo, SO: HABTM CakePHP : http://nuts-and-bolts-of-cakephp.com/2008/10/16/how-to-validate-habtm-data/

0

NOTEMPTY? im, , , .. category_id, . , , - , .

, ..:)

0

Source: https://habr.com/ru/post/1765786/


All Articles