如何使用grocery set_relation函数显示来自不同列中的两个不同表的内容 [英] How to use grocery set_relation function to display content from two different tables in different columns

查看:161
本文介绍了如何使用grocery set_relation函数显示来自不同列中的两个不同表的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用这些模式的表:

I have to tables with these schema:

users(id, name, email) 
user_details (id, user_id, physical_address, otherinfo)

我想在一个网格中显示两个表的所有内容grocery crud
当我尝试在第一个表上使用集合关系如图所示:注意:我已经还原了渲染视图的部分;

I would like to display all contents of both tables in one grid using grocery crud when i try to use set relation on the first table as shown: Note: I have reducted the part that does the rendering of the view;

$crud = new grocery_CRUD();
$crud->set_table('users');
$crud->set_relation('id', 'user_details', '{physical_address} + {otherinfo}');

id字段的值以及引用的表不会显示在网格中,因此它似乎不工作时使用主键。

the values of the id field as well as the referenced table don't appear in the grid, so it does not seem to work when using primary keys.

所以我决定从第二个表格的内容开始,如下:

So I decided to start with the contents of the second table like so:

$crud = new grocery_CRUD();
$crud->set_table('user_details');
$crud->set_relation('user_id', 'users', '{name} + {email}');

这是可行的,但问题是这些值出现在网格的一列。我想知道我如何可以将它们分离到不同的列,并使它们在单独的输入字段中可编辑。

This works, but the problem is that the values appear in one column in the grid. I would like to know how i can separate them to different columns and make them editable in separate input fields.

推荐答案

我的方式很可笑,

如果我真的需要字段分开,请使用 callback_column ,然后使用活动记录使用 $ row返回值 - > user_id ,并回调每个记录

my way kinda ridiculous,
if i were really need the field to be separated, i might use callback_column then use active records to return the value using $row->user_id, and callback each record

就像:

- > some_model-> get_name($ row-> user_id); 用于名称字段



this-> some_model-> get_name($ row-> user_id);

just like:
return $this->some_model->get_name($row->user_id); for name field
and
return $this->some_model->get_name($row->user_id); for email field

虚拟记录,它不能排序,(我不知道如果有人可以)

but, as i tested with some dummy records, it can't be sorted, (i dont know if anyone could)

这篇关于如何使用grocery set_relation函数显示来自不同列中的两个不同表的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆