Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6748613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:35:10+00:00 2026-05-26T12:35:10+00:00

For some reason i am unable to save HABTM relationships, I have checked the

  • 0

For some reason i am unable to save HABTM relationships, I have checked the data structure generated by the form and passed to the controller and also check the data structure in the model, and all seems to be inorder. Any help would greatly be appreciated.

    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;
                        //$dbo = $this->Product->getDatasource();
                        //$dbo->fullDebug = true;
                        if($this->Product->save()) {
                            $this->Product->commit();
                            //debug($dbo->_queriesLog); die;
                            $this->Session->setFlash( __('Product updated',true), 'flash_true');
                            $this->redirect(array('action' => 'view', $this->Product->field('slug')));
                  } else {
                            $this->Product->rollback();
                    $this->Session->setFlash(__('Please correct the errors below',true), 'flash_false');
                  }         
                    } else {
                        $this->data = $product;
                    }
                    $this->render('_form');
                    return;
                }
            }   
            $this->redirect(array('controller' => 'categories', 'action' => 'index'));
        }
    }

    class Product extends AppModel 
    {
        var $hasAndBelongsToMany = array(
            'Colors' => array(
                'className' => 'Color',
                'joinTable' => 'products_colors',
                'foreignKey' => 'product_id',
                'associationForeignKey' => 'color_id',
                'unique' => false,
            ),
            'Sizes' => array(
                'className' => 'Size',
                'joinTable' => 'products_sizes',
                'foreignKey' => 'product_id',
                'associationForeignKey' => 'size_id',
            ),
        );
    }


    <?php echo $this->Form->create('Product'); ?>
        <fieldset>
            <legend><?php __('Options') ?></legend>
        <?php echo $this->Form->input('Product.id') ?>
        <?php echo $this->Form->input('Product.product_category_id', array('label' => __('Category', true))) ?>
        <?php echo $this->Form->input('Sizes', array('label' => __('Sizes', true), 'multiple' => 'checkbox')) ?>
        <?php echo $this->Form->input('Colors', array('label' => __('Colors', true), 'multiple' => 'checkbox')) ?>  
        </fieldset>
        <fieldset>
            <legend><?php __('Product') ?></legend>
            <?php echo $this->Form->input('Product.sku') ?>
            <?php echo $this->Form->input('Product.price') ?>
            <?php echo $this->Form->input('Product.name') ?>
            <?php echo $this->Form->input('Product.description') ?>
            <?php echo $this->Form->input('Product.state', array('type' => 'checkbox')) ?>
        </fieldset>
    <?php echo $this->Form->end(__('Submit', true)); ?>
  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:35:11+00:00Added an answer on May 26, 2026 at 12:35 pm

    For anyone else facing this issue, Cakephp only supports id’s that are either INT() or CHAR(36). Using a non standard ID will result in a similar issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code in the Controller class and for some reason although
I have good familiarity with CSS but for some reason I am unable to
I am trying to use jquery.form.js and for some reason I am unable to
For some reason I am unable to view the button that I have included
For some reason I am unable to set and width properties of TD elements
I need something real simple, that for some reason I am unable to accomplish
For some reason im unable to solve this. what will be the Big-o Notation
For some reason Im unable to get the submit button below to re-enable once
For some reason I am unable to get the pattern match for preference_network_ followed
I am looking for some way to save dynamically generated image from WebBrowser control.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.