How to use the set_relation grocery function to display content from two different tables in different columns

I have tables with this schema:

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

I would like to display the entire contents of both tables in the same grid using grocery crud when I try to use the set relation in the first table, as shown: Note: I restored the part that renders 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 reference table, are not displayed in the grid, so when using primary keys it does not work.

So, I decided to start with the contents of the second table as follows:

 $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 ​​are displayed in a single column in the grid. I would like to know how I can split them into different columns and make them editable in separate input fields.

+4
source share
1 answer

my path seems ridiculous
if I really need the field to be split, I could use callback_column and then use active records to return the value using $row->user_id and call back each record

similar:
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 entries, it cannot be sorted (I don't know if anyone could)

0
source

All Articles