To get what you want you'll need to set 'unique' => false within your
declaration of HABTM association in your model.

//models/shop.php
var $hasAndBelongsToMany = array(
  'MainService' => array(
    'className' => 'MainService',
    'unique' => false,
  )
);

Here is the documentation of all the available key options for HABTM
and what they do:
http://book.cakephp.org/view/83/hasAndBelongsToMany-HABTM

Hope that helps,
Nick

On Mar 9, 6:20 am, Weather Forecaster <[email protected]> wrote:
> How do I make so that Cakephp not delete related records before
> adding, new.
>
> There are two models of Shop and MainService.
>
> Contact them so:
>
>      class Shop extends AppModel {
>
>          var $hasAndBelongsToMany = array(
>                 'MainService' =>
>                      array( 'className'              => 'MainService')
>                  );
>      }
>
> Stored in the form:
>
>      $this->Shop->saveAll($this->data);
>
> What happens to the base:
>
>      SELECT `ShopsMainService`.`main_services_id` FROM
> `shops_main_services` AS `ShopsMainService`     WHERE
> `ShopsMainService`.`carwash_id` = 71
>
>     DELETE `ShopsMainService` FROM `shops_main_services` AS
> `ShopsMainService` WHERE `ShopsMainService`.`carwash_id` = 71 AND
> `ShopsMainService`.`main_services_id` IN (41, 32, 30, 29, 27, 26, 23,
> 17, 13, 11, 7, 6, 4, 2)
>
>    INSERT INTO `Shops_main_services` (`carwash_id`,`main_services_id`)
> VALUES (71,'2'), (71,'4'), (71,'6'), (71,'7'), (71,'11'), (71,'13'),
> (71,'17'), (71,'23'), (71,'26'), (71,'27'), (71,'29'), (71,'30'),
> (71,'32'), (71,'41')
>
> How to disable the removal?
>
> The documentation is written here is  
> http://book.cakephp.org/view/75/Saving-Your-Data
>
> "By default when saving a HasAndBelongsToMany relationship, Cake will
> delete all rows on the join table before saving new ones. For example
> if you have a Club that has 10 Children associated. You then update
> the Club with 2 children. The Club will only have 2 Children, not
> 12."
>
> But how to do to disable the removal unclear.
>
> p.s.
>
> Ideally, it was good so CakePHP removed the missing connection add new
> ones, and existing ones are not touched.
>
> Example:
> The database is the connection with ID: 1,3,5,7
>
> Obtain new: 5,7,9
> It is necessary to: remove entries with the Id 1,3
>                             add 9
>                             and 5.7 remain unchanged.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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