Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter DataMapper ORM include_related always returning first row in database table
#1

[eluser]Andy78[/eluser]
I have a user model and a user_profile model and I am trying to get a specific user and the related user_profile with the following function. if I comment out the include_related line it works and gets the user based on user_id but if I try to use the include_related to pull in the users profile fields it just returns the first user object in the database and not the user based on user_id. Whats going wrong here?

Code:
function edit_admin_user(){
    //check user is logged in and has admin rights
    $this->login_manager->check_login(1);
    //get user id from the uri segment
    $user_id = $this->uri->segment(3);

    $user = new User();
    $user->get_by_id($user_id);
    //$user->include_related('user_profile', array('firstname','surname', 'telephone', 'address1', 'address2', 'city', 'postcode'), TRUE, TRUE)->get();

    //set the content for the view partial (this is the actual content of the page)
    $content_data['user'] = $user;

    $data['content'] = $this->load->view('admin/edit_admin_user', $content_data, TRUE);
    $data['page_title'] = 'Get Stuffed | Admin Area | Edit Admin User';

    $this->load->view('admin/index', $data);
}
#2

[eluser]Andy78[/eluser]
Sorry had a mental block I see where i am going wrong, should have been:

$user = new User();
$user->where('id', $user_id);
$user->include_related('user_profile', array('firstname','surname', 'telephone', 'address1', 'address2', 'city', 'postcode'), TRUE, TRUE)->get();






Theme © iAndrew 2016 - Forum software by © MyBB