I really don't know what else to do. I have checked my data against
the pages in frequent discussions and searched and read-through a lot
of posts. None actually helped me in this situation.
I am trying to save HABTM (in 1.2.6311). Problem is I don't get any
errors, I dont see any insets or updates in my sql debug. Nothing to
indicate that I am even trying to save. Here are all the details:
User HABTM Module
(Module HABTM User but that shouldn't even be necessary when saving
from the User side, right?)
Tables are up. Tables work. Manually adding to modules_users results
in a Module being loaded along with the User.
Creating a method for toggling user<->module links look like this:
users/toggle_module/2/1 (user_id / module_id)
function toggle_module($user_id = null, $module_id = null)
{
$user = $this->User->findById($user_id);
if ( $user && $module_id )
{
$this->User->toggleModule($module_id);
}else{
e('no user or no module id');
}
}
in User model:
function toggleModule($module_id)
{
$this->read();
$new_mod = $this->Module->findById($module_id);
if ( $new_mod )
{
$existing_ids = Set::extract($this->data['Module'], '{n}.id');
if ( in_array($new_mod['Module']['id'], $existing_ids) )
{
foreach ( $existing_ids as $i => $id )
{
if ( $id == $new_mod['Module']['id'] )
{
unset($existing_ids[$i]);
}
}
}else{
$existing_ids[] = $new_mod['Module']['id'];
}
unset($this->data['Module']);
sort($existing_ids); // desperate now...
$this->data['Module']['Module'] = $existing_ids;
debug($this->data);
$this->save($this->data); // also desperate since it should use
$this->data anyway
return true;
}else{
return false;
}
}
the prominent debug spits out this:
Array
(
[User] => Array
(
[id] => 2
[email] => [EMAIL PROTECTED]
[password] => very_secret_password_hash
[created] =>
[modified] => 2008-01-25 14:31:11
[name] => My Name
)
[Module] => Array
(
[Module] => Array
(
[0] => 1
[1] => 2
)
)
)
This is exactly what should be there, right? The Module with the id 2
is my manually added data and the id 1 is the new one to add. Even
though the save() is being run it decides to not perform any sql
updates or inserts. I have also tried using saveAll() but then I only
get a few more selects and transations... no writing to the database
at all.
I can not for the life of me figure out where my data is different
from the manual and the pages explaining all this. Where have erred?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---