小编Chr*_*ris的帖子

Cakephp HABTM没有保存

由于某种原因,我无法保存HABTM关系,我检查了表单生成的数据结构并传递给控制器​​,并检查模型中的数据结构,所有似乎都是有序的.任何帮助将不胜感激.

    CREATE TABLE `products_colors` (
      `product_id` char(36) NOT NULL DEFAULT '',
      `color_id` char(36) NOT NULL DEFAULT '',
      PRIMARY KEY (`product_id`,`color_id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

       CREATE TABLE `products_sizes` (
      `product_id` char(36) NOT NULL,
      `size_id` char(36) NOT NULL DEFAULT '',
      PRIMARY KEY (`product_id`,`size_id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

    class ProductsController extends AppController {
        function edit($id = null)
        {
            if(!is_null($id))
            {
                $this->set('productCategories', $this->Product->Category->find('list'));    
                $this->set('sizes', $this->Product->Sizes->find('list'));   
                $this->set('colors', $this->Product->Colors->find('list'));
                $this->Product->contain(array('Sizes', 'Colors'));
                $product = $this->Product->read(null, $id);
                if(!empty($product)) {
                    if($this->RequestHandler->isPut()) {
                        $this->Product->id = $id;
                        $this->Product->begin();
                        $this->Product->set($this->data);
                        debug($this->data); die; …
Run Code Online (Sandbox Code Playgroud)

cakephp has-and-belongs-to-many

2
推荐指数
1
解决办法
710
查看次数

标签 统计

cakephp ×1

has-and-belongs-to-many ×1