On Sat, Feb 23, 2008 at 4:46 PM, villas <[EMAIL PROTECTED]> wrote:
>
>  Thanks for the idea.  My set up is so simple that I can try anything
>  in seconds :)

Try:
$recursive = 2;
$this->User->find('[all|first|list]', $conditions, $fields, $recursive);


>  I commented out the key lines as you suggested and it just worked as
>  before,  it returned the [user] data but not the [group].  In other
>  words, no change.
>
>  I've been playing with this on and off since November and it has
>  worked yet!  If someone could post here the simplest working example,
>  I would be grateful.  Until then,  I'm sceptical that anyone actually
>  uses HABTM.  I can just imagine that everyone has given it a try and
>  then just found ways to work around the problem!
>

Try using the Bindable behavior. Comment out the binding params in
your models, leaving:

var $hasAndBelongsToMany = 'Group';
var $hasAndBelongsToMany = 'User';

class AppModel extends Model{
        var $actsAs = array('Bindable' => array('notices' => true));
...
}

UsersController:

$criteria = array(
        'conditions' => array('User.name' => 'foo'),
        'restrict' => array(
                'Group(id,name)'
        )
);
$this->set('users', $this->User->find('all', $criteria, null, null));


Here's a working example. This controller action is for a member
directory. An alphabetical list of links is provided, each passing its
letter. A list of members, with associated data, is returned.

function findByLetter()
{
        $letter = $this->params['letter'];
        $conditions = array(
                'conditions' => "LOWER(SUBSTRING(last_name, 1, 1)) = 
'${letter}'",
                'restrict' => array(
                        'MemberProfile(organisation)',
                        'Discipline(id,name_en,slug_en)'
                )
        );
        
        $this->Member->order = 'Member.last_name ASC';
        
        $this->set('letter', $letter);
        $this->set('members', $this->Member->find('all', $conditions, null, 
null));
        
        $this->Session->write('directory_search_url', "/members/${letter}");
        $this->render('list');
}


Array
(
    [Member] => Array
        (
            [id] => 802
            [created] => 2006-08-29 13:40:32
            [modified] => 2008-01-21 18:38:54
            [enabled] => t
            [member_type_id] => 3
            [first_name] => xxxx
            [last_name] => xxxx
            [slug] => xxxx_xxxx
            [full_name] => xxxx xxxx
        )

    [MemberProfile] => Array
        (
            [organisation] => xxxx
            [id] => 528
        )

    [Discipline] => Array
        (
            [0] => Array
                (
                    [id] => 1
                    [name_en] => Writing
                    [slug_en] => Writing
                )

            [1] => Array
                (
                    [id] => 2
                    [name_en] => Visual Arts
                    [slug_name_en] => Visual_Arts
                )
        )
)

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