views:

33

answers:

1

(CakePHP Version 1.3.4)

I have the following association between a Contact model with Account and Test models:

class Contact extends AppModel {
    var $name = 'Contact';

    var $actsAs = array('Containable');

    var $hasMany = array(
        'Test' => array(
            'className' => 'Test',
            'foreignKey' => 'contact_id',
            'dependent' => false
        )
    );

    var $belongsTo = array(
        'Account' => array(
            'className' => 'Account',
            'foreignKey' => 'account_id',                            
            'dependent' => false
        )
    );
}

The following query works just fine:

$contact = $this->Contact->find('first', array(
    'contain' => array(
        'Account', 'Test'
    ),

    'conditions' => array(
        'Contact.id' => $contactId
    )
));

But as soon as 'fields' are introduced the belongsTo association with Account breaks but the hasMany association with Test remains fine:

$contact = $this->Contact->find('first', array(
    'contain' => array(
        'Account', 'Test'
    ),

    'conditions' => array(
        'Contact.id' => $contactId
    ),

    'fields' => array(
        'Contact.id', 'Contact.first_name', 'Contact.last_name', 'Contact.account_id'    
    )
));

Does anyone else seem to have this problem?

A: 

Yeah, I've got exactly the same problem. I've got a Employee belongsTo Adress relation, and

$this->dataout = $this->Employee->find('all',array(
        'contain' => array('Address.full_name'),
        'fields' => array('Employee.id','Employee.address_id')
    ));

(where Address.full_name is a virtual Field). Without the fieldlist supplied, it works. Maybe file a bug report?

joni