morning mate,

If I understand what you're after exactly I think it is something I
was looking for just yesterday. In the end I came up with a not so
elegant solution which may work for you. But at the end of the day I
would love something a bit nicer.

In my model I:

1. Set up my HABTM relationships

In my component I:

1. grab the data

$this->{$this->modelClass}->id = $id;
$this->data = $this->{$this->modelClass}->read();

2. grab a complete list of related models (in my case it was tags for images)

$this->set('tags',$this->{$this->modelClass}->Tag->generateList());

3. Loop through the Tag element of my data array and create my own key
=> val list

        // associated tags
        $tags_associated = array();
        if (isset($this->data['Tag']) && is_array($this->data['Tag'])
&& count($this->data['Tag'])) {
                foreach ($this->data['Tag'] as $tag_info) {
                    $tags_associated[$tag_info['id']] = $tag_info['tag'];
                }
        }

4. set my tags associated array so i can access it from within my view
        $this->set('tags_associated',$tags_associated);

Then, in my view I:

1. output a select using these two arrays

<?php echo $html->selectTag('Tag/Tag', $tags, $tags_associated,
array('class' => 'fm-sct-multi', 'id'=>'fm-tags', 'multiple' =>
'1'),null,null,false); ?>

As I said, not the most elegant, could be better. But it works.

have fun,
freedom

On 18/08/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> I have 2 models:
>
> Users
> Counties
>
> I have set up User model with HABTM relationship, because a user has
> one or more counties with their account
>
> tables look like this
>
> users
>  - id
>  - username
>  - password
>  - email
>
> counties
>  - id
>  - county
>
> users_counties
>  - user_id
>  - county_id
>
> I need to generate a key=>val list of a user's counties to populate
> various select lists, I can't seem to make this work by just giving the
> relationships in the models, the SQL would look like:
>
> select County.id, County.count from counties as County INNER JOIN
> users_counties on County.id = users_counties.county_id where
> users_counties.user_id = ?
>
> I am needing to set the value of user_id by getting if from my Session
>
> Right now I have resorted to:
>   $u = $this->Session->read('User');
>   $this->User->id = $u['User']['id'];
>   $data = $this->User->read();
>
> Then I loop through $data['County'] and do my own select tag.
>
> I'm hoping there is an easier way, any help is appreciated.
>
> Thanks,
> Brian
>
>
> >
>

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

Reply via email to