Jump to content


set_model working but results are getting overwritten by crud

set_model where clause

  • Please log in to reply
3 replies to this topic

#1 ashish_nirkhe

ashish_nirkhe

    Member

  • Members
  • PipPip
  • 13 posts

Posted 07 September 2012 - 12:35 AM

Hi,
I have following in model file:

class custom_model extends grocery_CRUD_Model
{
   function join_table($table1, $table2, $userid)

    {
  
    //$selection_primary_key = $this->get_primary_key($field_info->device);
  //$query = $this->db->query("select * from device join user_device on device.id = user_device.device_id where user_device.user_id = 2");
  $this->db->select($table1.".*,".$table2.".*");
    $this->db->from($table1);
    $this->db->join($table2, $table2.".device_id". "=" .$table1.".id");
  $this->db->where("user_device.user_id",$userid);
    $results = $this->db->get()->result();
  var_dump ($results);
  return $result;
}
}

and then in the main function I am having:

$crud->set_model('custom_model');
$this->custom_model->join_table('device','user_device',$userid);
$crud->set_table('device');
  
  
    $crud->set_theme($this->theme);

    $crud->columns('device_id', 'product', 'build', 'description', 'device_status_id', 'preferred_location_id', 'owner_id', 'user_id', 'Access Group', 'showMap', 'Exception');

    $crud->set_relation('product','product','name');
    $crud->set_relation('build','build','build_id');
    $crud->set_relation('owner_id', 'user', 'email_address');
    $crud->set_relation('device_status_id', 'device_status', 'name');

    $crud->set_relation_n_n('preferred_location_id','location_device','preferred_location','device_id','preferred_location_id','name','priority');
    $crud->set_relation_n_n('user_id','user_device','user','device_id','user_id','email_address','priority');

    $crud->callback_column('User', array($this, 'getUser'));
    $crud->callback_column('Access Group', array($this, 'getAccessGroup'));
    $crud->callback_column('showMap', array($this, 'getCoordinate'));
    $crud->callback_column('Exception', array($this, 'getException'));
  
    $crud->unset_add();
    $crud->unset_edit();
    $crud->unset_delete();

    $output = $crud->render();
  $this->load->view('crud', $output);


now with this code i can see expected result in my var_dump
but in the list, which is being created with crud code, I again see all the records (and not the one restricted by where clause)

Can anyone please help me

Thanks a lot

#2 ashish_nirkhe

ashish_nirkhe

    Member

  • Members
  • PipPip
  • 13 posts

Posted 07 September 2012 - 06:08 PM

no one knows the solution? :(

#3 ashish_nirkhe

ashish_nirkhe

    Member

  • Members
  • PipPip
  • 13 posts

Posted 11 September 2012 - 08:00 PM

So finally done. I did some changes to few other functions and now it works. It also works with relation table.
so now where can be put for relation or selection table.

Thank you guys :)

#4 glats

glats

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 12 July 2013 - 10:54 PM

how can you did that? please i have the same problem







Also tagged with one or more of these keywords: set_model, where clause

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users