2011-11-26 56 views
0

我有2個表,用戶&國家注:表名是奇異PHP ADOdb的Active Record的關係設定

ADOdb_Active_Record::TableKeyBelongsTo(
    'user', // child table name 
    'id', // child primary key 
    'country', // parent table name 
    'country_id', // child foreign key 
    'id' // parent primary key 
); 

class User_Model extends ADOdb_Active_Record { 
    var $_table = 'user'; 
    ... 
} 

ADOdb_Active_Record::TableKeyHasMany(
    'country', // parent table name 
    'id', // parent primary key 
    'user', // child table name 
    'country_id' // child foreign key 
); 

class Country_Model extends ADOdb_Active_Record { 
    var $_table = 'country'; 
    ... 
} 

$user = new User_Model(); 
$user->load('id=1'); 

但這個錯誤出來

1146: Table 'happylucky.countries' doesn't exist 

          ADOConnection._Execute(SHOW COLUMNS FROM `countries`, false) % line 1017, file: adodb.inc.php 
         ADOConnection.Execute(SHOW COLUMNS FROM `countries`) % line 410, file: adodb-mysql.inc.php 
        ADODB_mysql.MetaColumns(countries) % line 390, file: adodb-active-record.inc.php 
        ADODB_Active_Record.UpdateActiveTable() % line 239, file: adodb-active-record.inc.php 
       ADODB_Active_Record.belongsTo(country, country_id, id, ADODB_Active_Record) % line 263, file: adodb-active-record.inc.php 

ADODB_Active_Record::UpdateActiveTable: Invalid table name: countries 
Fatal error: Class 'User' not found in /home/user/public_html/project/application/controllers/welcome.php on line 23 

是我的關係設定錯了嗎?或表名MUST是複數?

回答

0

您可以嘗試使用活動記錄

+0

它的工作原理之前設置

ADODB_Active_Record::$_changeNames = FALSE;

。謝謝 –