5.0.0 - 普通 - 已关闭
数据库:CREATE TABLE `fb_node` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`pid` int(11) NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB;
INSERT INTO `fb_node` VALUES (1, 0);
INSERT INTO `fb_node` VALUES (2, 1);
INSERT INTO `fb_node` VALUES (3, 2);
INSERT INTO `fb_node` VALUES (4, 3);
INSERT INTO `fb_node` VALUES (5, 4);
INSERT INTO `fb_node` VALUES (6, 5);Model:class Node extends \think\Model {
public function pnode () {
return $this->hasOne ('Node', 'id', 'pid');
}
}Controller: public function t () {
$a = Node::find (6);
$i = 0;
while ( ! empty ($a) && $i < 10) {
dump ($a->id);
$a = $a->pnode;
$i ++;
}
}期待的结果6
5
4
3
2
1
实际的结果 (死循环)
6
5
6
5
6
5
6
5
6
5
原因:
Model.php 中 getRelationData 的判断有误
