Sunday, June 10, 2012

Re: more than 1 level of belongsTo

I can't find what the problem is.
OK guys, here's more details:

This is main table that will be updated:
class AcctTab extends AppModel {
public $primaryKey = 'aacct';

public $belongsTo = array('CardAcctTab' => array('foreignKey'
=> 'aacct'));
}

This is intermediate table to get at the third one (CrefTab):
class CardAcctTab extends AppModel {
public $primaryKey = 'acct_no';

public $belongsTo = array('CrefTab' => array('foreignKey' =>
'card_no'));
}


This is the table we need some info from through the join:
class CrefTab extends AppModel {
public $primaryKey = 'cref_no';

public $virtualFields = array('id' => "rowid || ''",
'full_name' => "name || ' ' || name2");
}


Then in the controller I do:
$this->AcctTab->virtualFields['full_name'] = $this->CrefTab-
>virtualFields['full_name'];
$crefs = $this->AcctTab->find('all', array('fields' =>
array('aacct','CrefTab.cref_no','full_name','CrefTab.user_data','CrefTab.exp_dt'),
'recursive' => 2));
Generated query looks like
SELECT AcctTab.aacct, CrefTab.cref_no, CrefTab.user_data,
CrefTab.exp_dt, (name || ' ' || name2) AcctTab__full_name FROM
acct_tab AcctTab LEFT JOIN card_acct_tab CardAcctTab ON (AcctTab.aacct
= CardAcctTab.acct_no) WHERE (name || ' ' || name2) LIKE '%foo%'

ERROR ORA-00904: "NAME2": invalid identifier
name2 is in cref_tab which is never joined with..

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate