How about this behaviour:
http://bakery.cakephp.org/articles/view/add-delete-habtm-behavior
On Aug 29, 7:45 pm, LS <[EMAIL PROTECTED]> wrote:
> Hello, everyone!
>
> I would like a little help from you guys, if I may...
>
> I have 3 tables, wich are linked to each other with a "middle"
> controller...
>
> Transaction - TransactionCenter - Center
>
> These are the models:
>
> class Transaction extends AppModel {
> var $name = 'Transaction';
> var $belongsTo = array('Company', 'Person');
> var $hasMany = array('TransactionCenter');
>
> }
>
> class TransactionCenter extends AppModel {
> var $name = 'TransactionCenter';
> var $belongsTo = array('Transaction', 'Center');
>
> }
>
> class Center extends AppModel {
> var $name = 'Center';
> var $hasMany = 'Transaction';
> var $belongsTo = 'Account';
>
> }
>
> When the controller asks the model to save (with
> $this->Transaction->save($this->data)), it saves successfully, but only the
> Transaction
>
> model. Not the TransactionCenter.
>
> When I as a print_r($this->data), before saving, here's what I get:
>
> Array
> (
> [Transaction] => Array
> (
> [id] => 1
> [description] => Sistema Construtora
> [doc] =>
> [value] => 2200.00
> [due_date] => 2007-08-01
> [person_id] => 1
> )
>
> [TransactionCenter] => Array
> (
> [0] => Array
> (
> [transaction_id] => 1
> [amount] => 1500.00
> [porcentage] =>
> [center_id] => 1
> )
>
> [1] => Array
> (
> [transaction_id] => 1
> [amount] => 250.00
> [porcentage] =>
> [center_id] => 2
> )
>
> [2] => Array
> (
> [transaction_id] => 1
> [amount] => 155.55
> [porcentage] =>
> [center_id] => 3
> )
>
> [3] => Array
> (
> [transaction_id] => 1
> [amount] => 555.22
> [porcentage] =>
> [center_id] => 4
> )
>
> )
>
> )
>
> Can anyone give me a hand? I've been bumping into the wall with this
> for quite some time...
>
> I already have data in Transaction and TransactionCenter tables. I
> added some custom data directly into the database to have a test for
> my layout and such. I am now trying to make the edit action to work to
> later make the add action.
>
> The CREATE TABLE statements:
>
> CREATE TABLE `transactions` (
> `id` int(10) unsigned NOT NULL auto_increment,
> `created` datetime NOT NULL,
> `modified` datetime NOT NULL,
> `company_id` int(10) unsigned NOT NULL,
> `person_id` int(10) unsigned NOT NULL,
> `center_id` int(10) unsigned NOT NULL,
> `doc` varchar(50) collate utf8_unicode_ci default NULL,
> `due_date` date default NULL,
> `value` decimal(10,2) default NULL,
> `description` varchar(200) collate utf8_unicode_ci NOT NULL,
> PRIMARY KEY (`id`)
> ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
>
> CREATE TABLE `transaction_centers` (
> `transaction_id` int(10) unsigned NOT NULL,
> `center_id` int(10) unsigned NOT NULL,
> `amount` decimal(18,2) NOT NULL,
> `porcentage` decimal(18,2) default NULL,
> PRIMARY KEY (`transaction_id`,`center_id`)
> ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
>
> CREATE TABLE `centers` (
> `id` int(10) unsigned NOT NULL auto_increment,
> `created` datetime NOT NULL,
> `modified` datetime NOT NULL,
> `company_id` int(10) unsigned NOT NULL default '1',
> `account_id` int(10) unsigned default NULL,
> `name` varchar(250) collate utf8_unicode_ci NOT NULL,
> `startdate` date NOT NULL,
> `enddate` date default NULL,
> `person_id` int(10) unsigned default NULL,
> `protocol` varchar(250) collate utf8_unicode_ci default NULL,
> `number` varchar(250) collate utf8_unicode_ci default NULL,
> `description` text collate utf8_unicode_ci,
> PRIMARY KEY (`id`),
> UNIQUE KEY `UN_COMPANYID_NAME` (`company_id`,`name`)
> ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
>
> Thanks everyone.
>
> - LS
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" 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
-~----------~----~----~----~------~----~------~--~---