On 1/30/07, Sergei <[EMAIL PROTECTED]> wrote:
>
> Hello all,
>
> I've decided to try the example from documentation explaining HABTM
> association.
>
> I had setup posts, tags and posts_tags and proper association.

This is what I do - before I save the Photo which HABTM Tag and use
the returned array of ids in Photos

   function parseTags($tagString){
        $tags = explode(",",trim($tagString));
        foreach($tags as $tag){
                        if(!empty($tag)){
                        
$this->unbindModel(array('hasAndBelongsToMany'=>array('Photo')));
                        $tagRow = $this->findByTag($tag);
                        if(is_array($tagRow)){
                                // You can do $this->create() here
                                $ids[] = $tagRow['Tag']['id'];
                        }else{
                                //Code to insert the new tag
                                $newTag['Tag']['tag']=trim($tag);
                                $newTag['Tag']['id']="";
                                $this->save($newTag);
                                $ids[]=$this->getLastInsertId();
                        }
                        }
        }
        return $ids;
    }

Ugly but works

Tarique

-- 
=============================================================
PHP for E-Biz: http://sanisoft.com
Cheesecake-Photoblog: http://cheesecake-photoblog.org
=============================================================

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to