I still may add code to the testcase that would show the problem when
using a join table that does NOT have a primarykey id field.
If someone from core dev could confirm weather or not HABTM join
table's must have an id field or if the framework should be made to
work with HABTM join tables that do not have an id field this would
help.
In either case, I think if cake framework should require an id field
for the HABTM join tables we should add a warning or log entry that
shows the problem during debug >= 2 if a join table is missing the id
field.
If we would like to support HABTM join tables without a primary key
id, I'd be more than happy to add the testcases, I've built as well as
the fix that makes it possible.
Thanks in advanced
LunarDraco(mdcatc)
On Oct 15, 3:10 pm, LunarDraco <[EMAIL PROTECTED]> wrote:
> An update to this issue,
>
> After spending some time building testcases I've found that the
> correct fix is to add an 'id' to the mapping table.
> So in your case Posts_Tags needs an autoincrement 'id' int(10) field.
>
> On Oct 2, 9:57 pm, Action <[EMAIL PROTECTED]> wrote:
>
> > I have a form that displays all tags for a specified Post in a text
> > input field (separated by a space). If I add a tag to it and run the
> > save operation, everything goes fine. BUT, if I remove a tag and save,
> > it not only deletes the association with that Post, but also all
> > associations that tag has with other Posts from the join table. If I
> > set "unique" to true in the model, I have the opposite problem,
> > nothing gets deleted when I call the save operation.
>
> > My Controller:
>
> > function edit($id = null)
> > {
> > if($this->Session->read('login') != 'admin')
> > {
> > $this->redirect('/users/login');
> > }
> > if(!$id)
> > {
> > $this->redirect(array('action' => 'index'));
> > }
> > else
> > {
> > $this->pageTitle = 'Edit Post';
> > if(!empty($this->data))
> > {
> > $this->Post->create();
> > $this->data['Post']['id'] = $id;
> > $tags = explode(' ',
> > trim($this->data['Tag']['name']));
> > foreach($tags as $tag)
> > {
> >
> > $this->Post->Tag->create(array('name' => $tag));
> > $current_tag =
> > $this->Tag->findByName($tag);
> > if(is_array($current_tag))
> > {
> > $this->data['Tag']['Tag'][]
> > = $current_tag['Tag']['id'];
> > }
> > else
> > {
> > $this->Post->Tag->save();
> > $this->data['Tag']['Tag'][]
> > = $this->Post->Tag->id;
> > }
> > }
> > $this->Post->save($this->data);
> > $this->Session->setFlash('Your changes have
> > been saved.', $layout
> > = 'flash_success');
> > }
> > }
> > }
>
> > My Models:
>
> > var $hasAndBelongsToMany = array(
> > 'Tag' => array('className' => 'Tag',
> > 'joinTable' => 'posts_tags',
> > 'foreignKey' => 'post_id',
> > 'associationForeignKey' =>
> > 'tag_id',
> > 'conditions' => '',
> > 'fields' => '',
> > 'order' => '',
> > 'limit' => '',
> > 'offset' => '',
> > 'unique' => '',
> > 'finderQuery' => '',
> > 'deleteQuery' => '',
> > 'insertQuery' => ''),
> > );
>
> > var $hasAndBelongsToMany = array(
> > 'Post' => array('className' => 'Post',
> > 'joinTable' => 'posts_tags',
> > 'foreignKey' => 'tag_id',
> > 'associationForeignKey' =>
> > 'post_id',
> > 'conditions' => '',
> > 'fields' => '',
> > 'order' => 'Post.created
> > DESC',
> > 'limit' => '',
> > 'offset' => '',
> > 'unique' => '',
> > 'finderQuery' => '',
> > 'deleteQuery' => '',
> > 'insertQuery' => ''),
> > );
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---