Question

I am trying to make multiple relation on model as describes in cake kbook I have two model Account and Tax like this

Account(id, name, code) Tax(id.name, sales_tax_gl, purchase_tax_gl)

both sales_tax_gl and purchase_tax_gl related to Account.id these are the model I have created

class Tax extends AppModel {
var $name = 'Tax';
var $displayField = 'name';

var $belongsTo = array(
    'SalesTax' => array(
        'className' => 'Account',
        'foreignKey' => 'sales_tax_gl',
        'conditions' => '',
        'fields' => '',
        'order' => ''
    ),
    'PurchaseTax' => array(
        'className' => 'Account',
        'foreignKey' => 'purchase_tax_gl',
        'conditions' => '',
        'fields' => '',
        'order' => ''
    )
);
}


Account Model
class Account extends AppModel {
var $name = 'Account';
var$primaryKey = 'id';


var $hasMany = array(        
    'TaxSalesTax' => array(            
    'className' => 'Tax',            
    'foreignKey' => 'sales_tax_gl' ),        
    'TaxPurchaseTax' => array(            
    'className' => 'Tax',            
    'foreignKey' => 'purchase_tax_gl' ) 

);

}

But it fails with this message "Warning (2): pg_query() [function.pg-query]: Query failed: ERROR: missing FROM-clause entry for table "Account"

What'swrong with the model? I am using postgreSql, thank for your help

No correct solution

OTHER TIPS

In first model your model name is SalesTax and in the second one (Account Model) the model name is TaxSalesTax,please correct it into the correct one and try.

I am thinking that i found the problem. That's cause I use virtual fields in account model like below

var $name = 'Account';
var $primaryKey = 'id';
var $displayField = 'name';
var $order=array('Account.id');
var $virtualFields = array('dropdown_name' => 'Account.id || \' \' || Account.name');

when I uncomment $virtualFields it work as it should, but I still don't know why?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top