我有2张桌子,用户& country 注意:表名是单数
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
我的关系设置错了吗?或者表名必须是复数?
答案 0 :(得分:1)
您可以尝试设置
ADODB_Active_Record::$_changeNames = FALSE;
使用活动记录之前