简体   繁体   English

在杂货杂货店的多个表中列出

[英]Listing from multiple tables in grocery crud

I just started exploring grocery crud. 我刚刚开始研究杂货杂货。 I want list the values from multiple tables linked. 我想列出链接的多个表中的值。 As per their guide/tutorials I tried to figure out the solution, but couldn;t able to find solution. 根据他们的指南/教程,我试图找出解决方案,但无法找到解决方案。 Expected query and solution is on this link http://sqlfiddle.com/#!9/0c5faf/3 预期的查询和解决方案在此链接上http://sqlfiddle.com/#!9/0c5faf/3

$crud = $this->generate_crud('admin_users_groups');
$crud->where('group_id','3');
$crud->columns('user_id','DistID');
$crud->display_as('user_id','user');
$crud->set_relation('id', 'dist_info', 'ref_idkey');
//$crud->set_relation_n_n('groups', 'users_groups','groups','user_id','group_id','description');
//$crud->set_relation('user_id', 'admin_users', '{username} - {first_name}{last_name}');
//$crud->set_relation_n_n('DistID', 'admin_users','dist_info','id','id','ref_idkey');
//$crud->set_relation('user_id', 'admin_users', 'email');    
//$crud->set_relation_n_n('id', 'admin_users_groups', 'admin_users', 'id','dist_id', 'name');
//$crud->set_relation_n_n('groups1', 'admin_users_groups', 'admin_groups','user_id', 'group_id', 'name');`

Can any one help me to reach to desired solution? 谁能帮助我达成所需的解决方案?

You're just missing some columns in your table. 您只是缺少表中的某些列。 But the real trick is you basically want to display the id column twice, first to show the id and then in the set_relation call, but you can't do that as obviously the library won't know which one is supposed to go where. 但是真正的窍门是,您基本上想两次显示id列,首先显示id,然后在set_relation调用中,但是您不能这样做,因为很明显,该库不知道哪个应该放在哪里。 You have two choices, create a custom model to allow a join of the two tables or use a callback to manually go get the data you need. 您有两种选择,创建一个自定义模型以允许两个表的联接,或者使用回调手动获取所需的数据。 The second choice should be much easier: 第二种选择应该容易得多:

$crud = $this->generate_crud('admin_users_groups');
$crud->where('group_id','3');
$crud->columns('id, 'group_id, 'user_id','DistID')
$crud->display_as('user_id','user');
$crud->callback_column('DistID', array($this, 'callback_distID');
...
}

public function callback_distID($value, $row) {
    //Load your model for the 'dist_info'
    $this->load->model('Dist_info_model);
    $dist = $this->Dist_info_model->get_dist_info($row->id);
    return $dist['ref_idkey'];

Then in your model: 然后在您的模型中:

public function get_dist_info($id) {
    return $this->db->getwhere('Dist_info', array('recid'=>$id))->row_array; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM