Saving HABTM problems

2009-07-14 Thread cc_humbry

Hi,
Can't figure this one out, not for the want of trying though.

Models involved are Category, CandidateItem which are associated in
each model as HABTM. I created a temp baked project to see if the
association definition was correct and it appears to be.

In my categories_controller I have a method which is called via AJAX
from a categories view. The method does stuff that returns an array of
strings which I want to create CandidateItems from. I have tried a
number of ways to do this. Firstly with a large array thus:
$data = array();
$data["Category"]["id"] = $categoryId; // set previously
foreach($titles as $title) {
$data["CandidateItem"]["CandidateItem"][$count]["title"] = $title;
$data["CandidateItem"]["CandidateItem"][$count]["category_id"] =
$categoryId;
}
$this->Category->save($data);

This doesn't save anything, just updates the last modified date on the
Category.

I have tried similar to above where in the foreach loop I
{
 $data = array();
$data["CandidateItem"]["title"] 
= $item;

$data["CandidateItem"]["category_id"] = $categoryId;

$this->CandidateItem->create($data);

$this->CandidateItem->save($data);
}

which does save new CategoryItems but doesn't save any association
data in the category_items_categories table.

What am I doing wrong? Some pointer would be most welcome as all the
docs appear to discuss creation of HABTM associations from a view (and
therefore discuss what needs to go in there) I can find nothing on
this particular use case.

Thanks
Conrad

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



saving HABTM problems

2007-08-08 Thread [EMAIL PROTECTED]

Hi all, as a nwbie to CakePHP, I experience problems understanding how
the whole HABTM mechanism work.

So here is the point, I got 2 tables publishers and places related by
a HABTM condition.

First, I save the publisher data and then the place data and then I
try to add the record to the HABTM table.

I'm using this method: 
http://bakery.cakephp.org/articles/view/add-delete-habtm-behavior
but can't understand something. How can you save something in ths join
table if you don't have saved it before in both tables?

So, let's recap,
I save the data from publisher
I save the data from place
and then try to use the habtmAdd function used in the link given.

The data I got at this point is:
Array
(
[Publisher] => Array
(
[id] => 40
[company_id] => 153
[first_name] => Martin
[last_name] => Ratinaud
[created] => 2007-08-08 18:51:21
[modified] => 2007-08-08 18:51:21
)

[Place] => Array
(
[Place] => Array
(
[0] => 13
)

)

)

but I don't manage to have anything in my join table.

Thanks in advance


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---