/models/users.php
class User extends AppModel {
public $name = 'User';
public $hasAndBelongsToMany = array(
'Fundraiser' => array(
'className' => 'Fundraiser',
'joinTable' => 'fundraisers_users',
'foreignKey' => 'user_id',
'associationForeignKey' => 'fundraiser_id',
'with' => 'FundraisersUser',
'unique' => false
)
);
}
/models/fundraisers.php
class Fundraiser extends AppModel {
public $name = 'Fundraiser';
public $hasAndBelongsToMany = array(
'User' => array(
'className' => 'User',
'joinTable' => 'fundraisers_users',
'foreignKey' => 'fundraiser_id',
'associationForeignKey' => 'user_id',
'with' => 'FundraisersUser',
'unique' => false
)
);
}
/models/fundraisers_user.php
class FundraisersUser extends AppModel {
public $name = 'FundraisersUser';
public $belongsTo = array('User', 'Fundraiser');
}
Debug output:
7 START TRANSACTION 0 0
8 START TRANSACTION 0 0
9 INSERT INTO `users` (`first_name`, `last_name`, `username`,
`password`, `created`) VALUES ('', '', '', '', '2009-03-21 01:25:08')
1 0
10 SELECT LAST_INSERT_ID() AS insertID 1 1 0
11 SELECT `FundraisersUser`.`fundraiser_id` FROM `fundraisers_users`
AS `FundraisersUser` WHERE `FundraisersUser`.`user_id` = 12 0
0 0
12 INSERT INTO `fundraisers_users` (`user_id`,`fundraiser_id`) VALUES
(12,0), (12,1) 1452: Cannot add or update a child row: a foreign key
constraint fails (`db_frontrunner_01/fundraisers_users`, CONSTRAINT
`user_fundraiser_fk2` FOREIGN KEY (`fundraiser_id`) REFERENCES
`fundraisers` (`id`)) 0
13 COMMIT
Notice, fundraisers table isn't populated, what is even odder, it
looks like it is trying to get a fundraiser_id from the join table.
And it is attempting to put two rows into the fundraisers_users table
with weird ids. Not to mention the other fields in fundraisers_users
are not being populated as well. What am I doing wrong?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---