How to use grocery set_relation function to displa

2019-05-10 00:08发布

I have to tables with these schema:

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

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}');

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.

1条回答
够拽才男人
2楼-- · 2019-05-10 00:45

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

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)

查看更多
登录 后发表回答