I am working on a project that involves a lot of many to many
relationships, and for some reason cakephp isn't playing nice with
them. Take the following tables:
Table: contacts
id
name
created
updated
Table: phones
id
number
Table: contacts_phone
contact_id
phone_id
Here are my two models:
class Contact extends AppModel{
var $name = 'Contact';
var $hasAndBelongsToMany = 'Phone';
}
class Phone extends AppModel{
var $name = 'Phone';
var $hasAndBelongsToMany = 'Contact';
}
The controller:
function add(){
if(!empty($this->data)){
if($this->Contact->saveAll($this->data)){
$this->Session->setFlash('Contact has been saved');
}
}
}
And the view:
<h1>Add Contact</h1>
<?php
echo $form->create('Contact');
echo $form->input('Contact.name');
echo $form->input('Phone.0.number');
echo $form->end('Save');
?>
The result?
1 START TRANSACTION 0 0
2 INSERT INTO `contacts` (`name`, `updated`, `created`) VALUES
('Mark', '1268143497', '1268143497') 1 0
3 SELECT LAST_INSERT_ID() AS insertID 1 1 0
4 SELECT `ContactsPhone`.`phone_id` FROM `contacts_phones` AS
`ContactsPhone` WHERE `ContactsPhone`.`contact_id` = 3 0 0 0
5 COMMIT 0 0
What am I missing?
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