> Aha! I think I actually had it right before, but Cake appears to care
> about the order of the top-level array. So if it goes ('Post', 'Tag')
> it works but if it goes ('Tag', 'Post) it doesn't.
>
> It would be neat if a future version of Cake could take this a step
> further and create associated records on the fly. So if instead of
> supplying an ID you supplied an array of fields (like you do for a
> normal save operation), it would create the relevant tag record. Right
> now saving with existing tags is easy, but I still need to create new
> ones manually.
>

here's a snippet from one of my controllers, it makes it possible to
have a single text input, into which people enter their tags as a
comma separated list. It checks to see if a tag already exists before
creating the association.

$i = 0;
            foreach ($tags as $tag)
            {
                if ($tag != " " && $tag != "")
                {
                    $tag = trim($tag);

                    if (!$result = $this->Controller->Tag->findByName ($tag))
                    {
                        $data['Tag'] = array();
                        $data['Tag']['id'] = null;
                        $data['Tag']['name'] = $tag;
                        $data['Tag']['handle'] =
$this->Sanitize->paranoid($tag);
                        $data['Tag']['description'] = null;
                        $this->Controller->Tag->save($data);
                        $result = $this->Controller->Tag->read();
                    }
                }
                $this->params['data']['Tag']['Tag'][$i] = $result['Tag']['id'];
                ++$i;
            }

$this->Controller->save($this->params['data']);

hth

jb

-- 


jon bennett
t: +44 (0) 1225 341 039 w: http://www.jben.net/
iChat (AIM): jbendotnet Skype: jon-bennett

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

Reply via email to