Saturday, October 4, 2008

Re: How to save extra field in join table in HATBM Cake1.2

Hi Andre,

I use the the following behavior: http://bakery.cakephp.org/articles/view/add-delete-habtm-behavior

In the comments of that article someone posted a modification for the
addHabtm-method in order to save extra data, and there you also find
an updateHabtm-method for updating the extra data.

But I remember a problem with addHabtm, because the model save()-
function rebuilds all associated datasets, the extra data of all
datasets got deleted whenever something was added. To avoid that I
replaced the save statement with an insert-query, not beautiful but
did the job.

// $success = $model->save($data);
$success = mysql_query('INSERT INTO '.$joinTable." (".$foreignKey.", ".
$assoc."_id) VALUES (".$id.", ".$assoc_ids[0].")");
(I just notice that it only works for single additions, obviously I
didn't need more *g* But it should be an easy one to loop over all
assoc_ids.)

This is quite a while ago and might not be the best solution with the
latest cakePHP, but I thought I just let you know.

Hope this helps anyway,

Michael


On 4 Okt., 18:28, Andre <andre_susan...@yahoo.com> wrote:
> Hi all,
> I saw "Storing additional data on join table"https://trac.cakephp.org/ticket/828.
> Having, two tables associated with HABTM: tags, posts, posts_tags
> posts_tags{ post_id,tag_id,weight }
>
> Can anyone help me showing how to use it, in the Post 's add or Post
> 's edit view in to populate "weight" field in posts_tags.weight
> column?
>
> I am thinking to use Checkbox options to select related
> posts_tags.weight, And input text to enter weight.
>
> I've been struggling with this issue for few weeks with HABTM where
> the join table record is deleted and reinserted everytime, thus the
> posts_tags.weight column were never saved?
>
> Thanks
--~--~---------~--~----~------------~-------~--~----~
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+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: