Please excuse this cake newbie here, I know I must have done something
wrong but I simply cannot figure out what I did wrong. I have a model
called Guild that is using Sluggable, Containable and Transaction
Behaviors.
I added a convenience function, called createNewGuild, that is
supposed to create a new guild record and update the guild_id and
guild_rank fields in a character record. The code is listed here:

function createNewGuild($character_id, $guild_name) {
$guild = array('leader_id' => $character_id, 'name' => $guild_name);

// Begin Transaction
$this->begin();

$this->create();
if ($this->save($guild)) {
        // Set character's guild_id
        $this->Leader->id = $character_id;
        if ($this->Leader->saveField('guild_id', $this->id)) {
                // Set character's guild_rank to Leader (2)
                if ($this->Leader->saveField('guild_rank', '2')) {
                        // All records have been updated properly.
                        // Commit this Transaction
                        $this->commit();
                        return true;
                }
        }
}

// To reach this point, something must have gone wrong...
// Rollback Transaction
$this->rollback();
return false;
}

However when I call this function from a controller in debug mode, the
field guild_rank is never updated and I can't see what I have done
wrong. The debug output gives me the following series of sql
statements and as you can see, there isn't any UPDATE statement for
guild_rank :
SET autocommit=0
begin
SELECT `Guild`.`id`, `Guild`.`slug` FROM `guilds` AS `Guild` WHERE
`Guild`.`slug` = 'LIKE test-guild%'
INSERT INTO `guilds` (`leader_id`,`name`,`slug`,`id`) VALUES
('48438309-8914-4238-b830-0071077a7f0f','Test Guild','test-
guild','48689f9c-1664-49e9-82fc-00a2077a7f0f')
SELECT COUNT(*) AS `count` FROM `characters` AS `Leader` WHERE
`Leader`.`id` = '48438309-8914-4238-b830-0071077a7f0f'
UPDATE `characters` SET `guild_id` =
'48689f9c-1664-49e9-82fc-00a2077a7f0f' WHERE `characters`.`id` =
'48438309-8914-4238-b830-0071077a7f0f'
SELECT COUNT(*) AS `count` FROM `characters` AS `Leader` WHERE
`Leader`.`id` = '48438309-8914-4238-b830-0071077a7f0f'
commit
SET autocommit=1

Any ideas?
--~--~---------~--~----~------------~-------~--~----~
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