【发布时间】:2015-05-23 02:30:14
【问题描述】:
这是我需要的数据库结果
{comment: 'hello there', user: [{name: 'sahan', id: 1}], id: 2}
用于获取 cmets 的函数
public function get_comments(){
$query = $this->db->get('comments');
return $query->result_array();
}
我有一个 cmets 表和一个 users 表,当用户 cmets 在某事上时
comment is saved as follows
comment > Comment text
user: userid
因此,当显示数据时,我需要 codeigniter 使用从用户表中找到的用户数据填充用户字段
有人知道怎么做吗? 我在 SailsJS 中使用了此功能,但不知道如何在 CodeIG 中执行此操作 Sails.js populate nested associations
【问题讨论】:
-
我们能看到您用来从数据库中提取 cmets 的代码吗?
-
有什么想法@nivixzixer好吗?
-
只是好奇,但你为什么要将用户数据放在一个数组中?每个评论只有一个用户,对吧?
-
这样我就可以轻松呈现我的观点,你知道谁发表了评论等等
标签: sql codeigniter sails.js