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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.