我有3张桌子-
users(id,name,dob)
books(id,title,author)
issuedbooks(id,book_id,student_id,issue_date)
用户与书籍之间的关系是多对多的,导致第三表发行书籍。
我的模型是-
class student extends DataMapper{
var $table="students";
var $has_many=array(
"books"=>array(
"class"=>"book",
"join_table"=>"issuedbooks",
"join_self_as"=>"student",
"join_other_as"=>"book",
"other_field"=>"students"
)
);
}
class book extends DataMapper{
var $table="books";
var $has_many=array(
"students"=>array(
"class"=>"student",
"join_table"=>"issuedbooks",
"join_self_as"=>"book",
"join_other_as"=>"student",
"other_field"=>"books"
)
);
}
这张表发行的书有类似的条目 -
id student_id book_id issue_date
1 2 1 2013-07-18
2 2 4 2013-07-16
3 1 5 2013-07-18
4 2 6 2013-07-18
现在我必须找出所有由 id 为 2 且 issue_date 为 2013-7-17 的学生选择的书籍。
我试过了,但不会得到任何结果。
$student=new student();
$student->get_by_id('2');
$student->books->include_join_fields()->get();
foreach($student->books as $book):
$book->where_join_field($student,'issue_date >',"2013-07-17")->get();
echo $book->title." ".$book->join_issue_date."<br />";
endforeach;
请帮帮我,我哪里出错了?