我正在Codeigniter 2.1.2:中使用DataMapper ORM
我有这样的实体:
Person
-id PRIMARY KEY
-name
-lastname
-age
Student
-person_id PRIMARY KEY
-college
-notebook_color
-other attribute
Address
-id PRIMARY KEY
-street
-number
-person_id
注意:学生没有自己的PK。它使用个人ID作为PK。
所以我的问题是。我想创建一个学生:
$student = new Student();
$student->get_by_person_id($id);
我希望$student
拥有person
的所有数据,包括加法器。我尝试使用include_related()从person
中引入字段,但这并没有带来相关的对象。我希望我的$student
看起来像:
$student ->id
->name
->lastname
->age
->college
->notebook_color
->other_attribute
->address (array)
[0] -> id
-> street
-> number
[1] -> id
-> street
-> number
我怎样才能让它发挥作用?
不能有名为"person_id"的PK。Datamapper要求所有PK都被称为"id"。FK应该由它们的关系名称来调用,并以"_id"作为后缀。因此,地址中的FK应称为"student_id"。
此外,Datamapper不支持复合。因此,无法合并Person和Student的记录。