0
class Post extends AppModel {
    var $name = 'Post';
    var $hasMany = array(
        'CategoryPost' => array(
            'className' => 'CategoryPost'
        )
    );
    var $belongsTo = array(
        'Page' => array(
            'className' => 'Page'
        )
    );

class Category extends AppModel {
    var $name = 'Category';
    var $hasMany = array(
        'CategoryPost' => array(
            'className' => 'CategoryPost'
        )
    );

class CategoryPost extends AppModel {
    var $name = 'CategoryPost';
    var $validate = array(
        'category_id' => array(
            'rule'     => array('multiple', array('in' => array(1, 2, 3, 4))),
            'required' => FALSE,
            'message'  => 'Please select one, two or three options'
        )
    );
    var $belongsTo = array(
        'Post' => array(
            'className' => 'Post'
        ),
        'Category' => array(
            'className' => 'Category'
        )
    );

Will this be the correct format of array that is needed to save this with saveAll? This doesn't save the CategoryPost model. If it isn't what should be the format of the array?

Array
(
    [Post] => Array
        (
            [title] => query
            [body] => 

query

            [page_id] => 122
            [modified] => 2010-12-30 23:33:47
            [created] => 2010-12-30 23:33:47
            [uri] => query-9
        )

    [CategoryPost] => Array
        (
            [0] => Array
                (
                    [category_id] => 1
                )

            [1] => Array
                (
                    [category_id] => 2
                )

        )

    [Page] => Array
        (
            [meta_keywords] => query
            [meta_description] => query
            [title] => query
            [layout] => index
        )

)
Teej
  • 12,764
  • 9
  • 72
  • 93

1 Answers1

0

Well, everthing seems fine, and the CategoryPost data should be saved.

Maybe comment out the validation from the CategoryPost model and try then.

pawelmysior
  • 3,190
  • 3
  • 28
  • 37