2014-03-07 45 views
0

我有一個非常混亂的問題有關係涉及..的DataMapper在代碼點火器與許多許多

我配置數據映射,並開始使用代碼點火器使用它..我有這個類:

class FamilyMemberDetail extends DataMapper { 
var $table = "family_members_details"; 
var $has_one = array('gender', 'maritalstate'); 

public function __toString() { 
    return is_string($this->id) ? $this->id : ""; 
} 

} 

對於性別它工作正常..

class Gender extends DataMapper { 
var $table = "genders"; 
var $has_many = array("familymemberdetail"); 

public function __toString() { 
    return is_string($this->gender_label) ? $this->gender_label : ""; 
} 

} 

但隨着婚姻狀況:

class MaritalState extends DataMapper { 
var $table = "marital_state"; 
var $has_many = array("familymemberdetail"); 

public function __toString() { 
    return is_string($this->marital_state_label) ? $this->marital_state_label : ""; 
} 

} 

我得到這個錯誤!

Error Number: 1146 

Table 'elkhoudary_family.kh_family_members_details_marital_state' doesn't exist 

SELECT `kh_marital_state`.* FROM (`kh_marital_state`) LEFT OUTER JOIN `kh_family_members_details_marital_state` kh_family_members_details_marital_state ON `kh_marital_state`.`id` = `kh_family_members_details_marital_state`.`maritalstate_id` WHERE `kh_family_members_details_marital_state`.`familymemberdetail_id` = 1 

Filename: C:\AppServ\www\elkhoudary\system\database\DB_driver.php 

Line Number: 330 

的問題是,我並沒有說明這種關係需要一個連接表,但.. CI堅持認爲,它需要之間的表..是不是應該像性別工作..什麼我在這裏想念嗎?

回答

0

好的我發現了爲什麼,它真的很愚蠢..關係列應該命名爲[className] _id不是[tableName] _id,因爲我有我的類名爲「MaritalState」和我的表名「marital_state」。

所以我改變了所有實體「_的,而不是駱駝情況下,一切都很好..

class Family_member_detail extends DataMapper { 
var $table = "family_members_details"; 
var $has_one = array('gender', 'marital_state'); 

public function __toString() { 
    return is_string($this->id) ? $this->id : ""; 
} 

} 

性別:

class Gender extends DataMapper { 
var $table = "genders"; 
var $has_many = array("family_member_detail"); 

public function __toString() { 
    return is_string($this->gender_label) ? $this->gender_label : ""; 
} 

} 

婚姻狀態:

class Marital_state extends DataMapper { 
var $table = "marital_state"; 
var $has_many = array("family_member_detail"); 

public function __toString() { 
    return is_string($this->marital_state_label) ? $this->marital_state_label : ""; 
} 
}