id | shop_id | service_id | price
And when I change the data, I lose the field price
Ahh, so we're not talking about a standard HABTM as the join table has
extra fields. Surely whenever adding/editing links you will also need
to show the price incase it needs updating. So why are you not
@WebbedIT
I need to keep the old records as I am in them to store additional
information.
In tabel ShopsMainService i write down the price of services. and I
get
id | shop_id | service_id | price
And when I change the data, I lose the field price
On Mar 10, 11:02 am, WebbedIT
@WebbedIT
'unique' = false does indeed stop cake from running a deleteAll on
the join table before inserting new records. The benefit of this is
it makes adding additional 'tags' much easier. Consider the
following: If all you want to do is add a new link between two models,
if unique is set to
@Weather
It is standard practice on a HABTM join table to delete all existing
records then run a new insert, this is the most efficient way to do it
as requires fewer SQL calls and PHP loops, plus it ensures there is no
duplication of selected options which would cause problems at a later
date
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
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'