CakePHP containables - Working backwards

72 Views Asked by At

I have a database of Clients. Each Client can have many Contracts. Each Contract contains many Invoices.

In the Invoice view, i'm trying to display the client_name, but I only have the contract_id with which to link the Invoice to the Client.

I have tried the following, but I can only retrieve the Invoice and Contract details when debugging out the array:

public function view($id = null) {
    $this->Invoice->id = $id;
    if (!$this->Invoice->exists()) {
        throw new NotFoundException(__('Invalid invoice'));
    }
    $payment = $this->Invoice->find('first', array(
        'conditions' => array(
            'Invoice.id' => $id
        ),
        'contain' => array(
            'Contract' => array(
                 'Client'
             ) 

        )
    ));
    $this->set('Invoice', $this->Invoice->read(null, $id));
}
0

There are 0 best solutions below