Jump to content

Including indirectly related table data using cakephp


jholcomb

Recommended Posts

The issue I have is probably a simple one but I am just not getting it and can't find anything on the web to help me.

 

What I have is 3 tables, Table1(PotentialLoan) is related to Table2(SalesPerson) and Table2 is related to Table3(Dealer). Table1 is not related directly to Table3. What I am trying to do is fill out a form, submit it and then create a print page from the data just entered. My print page requires information from Table3 based on the association with Table2.

 

PotentialLoans has a field named sales_person_id linking it to the SalesPeople table

I then have a field named dealer_id in the SalesPeople table linking it to the Dealers table

 

I am looking for the best way to get the dealer information based on the salesperson id in order to show in my view

 

The latest attempt looks like this

 

public function reply($id = null) {
	$this->PotentialLoan->id = $id;
	if (!$this->PotentialLoan->exists()) {
		throw new NotFoundException(__('Invalid potential loan'));
	}
	$this->set('potentialLoan', $this->PotentialLoan->read(null, $id));
	$this->set('dealer', $this->PotentialLoan->SalesPerson->Dealer->find('first', $id));
}

 

This appears to work until you look closer and realize that you are not getting the correct dealer information. All the associations are set up correctly in the models.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.