Hello,

The problem is in the title "Cake not saving CREATED and MODIFIED
field to the join table when saving related records", here's the
models involved:

-- -----------------------------------------------------
-- Table `dbname`.`user`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `dbname`.`user` (
  `id` INT NOT NULL AUTO_INCREMENT ,
  `first_name` VARCHAR(255) NOT NULL ,
  `last_name` VARCHAR(255) NOT NULL ,
  `street_address` VARCHAR(255) NULL ,
  `postal_code` VARCHAR(5) NULL ,
  `city` VARCHAR(255) NULL ,
  `phone` VARCHAR(255) NOT NULL ,
  `email` VARCHAR(255) NULL ,
  `gender` INT(1) NOT NULL ,
  `username` VARCHAR(45) NULL ,
  `password` VARCHAR(255) NULL ,
  `active` BOOLEAN NOT NULL DEFAULT 1 ,
  `registered` BOOLEAN NOT NULL DEFAULT 1 ,
  `created` DATETIME NULL ,
  `modified` DATETIME NULL ,
  PRIMARY KEY (`id`) )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `dbname`.`usergroup`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `dbname`.`usergroup` (
  `id` INT NOT NULL AUTO_INCREMENT ,
  `name` VARCHAR(255) NOT NULL ,
  `created` DATETIME NULL ,
  `modified` DATETIME NULL ,
  PRIMARY KEY (`id`) )
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `dbname`.`user_usergroup`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `dbname`.`user_usergroup` (
  `id` INT NOT NULL AUTO_INCREMENT ,
  `user_id` INT NOT NULL ,
  `usergroup_id` INT NOT NULL ,
  `created` DATETIME NULL ,
  `modified` DATETIME NULL ,
  PRIMARY KEY (`id`) )
ENGINE = InnoDB;

And cake models:

<?php
class User extends AppModel {
    var $useTable = 'user';
    var $actsAs = array('Containable');
    var $hasAndBelongsToMany = array(
        'Usergroup' =>
            array(
                'className'              => 'Usergroup',
                'joinTable'              => 'user_usergroup',
                'foreignKey'             => 'user_id',
                'associationForeignKey'  => 'usergroup_id',
                'unique'                 => true
            )
    );
}
?>

<?php
class Usergroup extends AppModel {
    var $useTable = 'usergroup';
    var $hasAndBelongsToMany = array(
        'User' =>
            array(
                'className'              => 'User',
                'joinTable'              => 'user_usergroup',
                'foreignKey'             => 'usergroup_id',
                'associationForeignKey'  => 'user_id',
                'unique'                 => true
            )
    );
}
?>

And here is the view I'm using to send the form data:

<?php
    echo $form->create('User', array('url' => array('controller' => '/
user', 'action' => 'set_usergroups')));
    echo $form->input('id', array( 'type' => 'hidden' ) );
    echo $form->input('Usergroup.Usergroup', array(
       'type' => 'select',
       'multiple' => 'checkbox',
       'options' => $usergroupList,
       'label'=> __('usergroups', true)
    ));
    echo $form->end(__('save', true));
?>

And here's the relevant part's from controller:

<?php
    function set_usergroups($id = null) {
        if (!empty($this->data)) {
            if ($this->User->save($this->data)) {
                $this->Session->setFlash(__('data saved successfully',
true));
            } else {
                $this->Session->setFlash(__('error while saving data',
true));
            }
        }
        $this->User->id = $id;
        $this->data = $this->User->read();
        $usergroupList = $this->User->Usergroup->find('list');
        $this->set('usergroupList', $usergroupList);
    }
?>


So... Cake creates the records to the user_usergroup join table OK,
but it does not set the CREATED and MODIFIED field dates. Can someone
give help with that?

Thanks!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to