halo,
i have a question about the HABTM relationship
let me use the most common example on web
there are 3 table database:
1. posts (post_id, name)
2. posts_tags (post_id, tag_id)
3. tags (tag_id, name)
and let's take a look on the tags table
tag_id name
-------------------
1 David
2 Terry
3 Ronaldo
and then i created a view for edit.ctp the Post.
in the post controller
----------------------------------------------------------------------------
$ names = $this->Post->Tag->find('list',array('fields'=>array('tag_id',
'name)));
$this->set(compact('names'));
In the view, I created a form to update the posts
----------------------------------------------------------------------------
<tr>
<td valign=top>Who is tagged (Name)</td>
<td><?php echo $form->input('Tag.Name' ,array('label'=>false));
?></td>
</tr>
now i can update the Post and select who was tagged in it without any
problem.
here my question comes:
as more ppl are added in the tags table i added another column
tag_id name familyname
----------------------------------
1 David Beckham
2 John Terry
3 Christano Ronaldo
4 David Terry
Since the controller create a key value pair (tag_id and name only), so now
there are 4 options which are David, John, Christano and David. There are 2
David now!
I would like to add another input for family name in the view. Sth like
<tr>
<td valign=top>Who are tagged (Name)</td>
<td><?php echo $form->input('Tag.Name' ,array('label'=>false)); ?></td>
</tr>
<tr>
<td valign=top>Who are tagged (Family Name)</td>
<td><?php echo $form->input('Tag.FamilyName' ,array('label'=>false));
?></td>
</tr>
But I dun know how to make it works?
I know I can combine the name and family name such that one tag_id is mapped
to one name to solve this problem. But I just wanna know whether it is
possible for one key to be mapped with more than one values.
Thanks very much for your help.:-)
kit
--
View this message in context:
http://n2.nabble.com/HABTM-problem-tp2363919p2363919.html
Sent from the CakePHP mailing list archive at Nabble.com.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---