CodeIgniter DataMapper ORM include_related винаги връща първия ред в таблицата на базата данни

Имам потребителски модел и модел user_profile и се опитвам да получа конкретен потребител и свързания с него user_profile със следната функция. ако коментирам линията include_related, тя работи и получава потребителя въз основа на user_id, но ако се опитам да използвам include_related, за да изтегля полетата на потребителския профил, той просто връща първия потребител в базата данни, а не потребителя въз основа на user_id. Какво не е наред тук?

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

person user794846    schedule 21.03.2012    source източник


Отговори (1)


Имах умствен блок, трябваше да е:

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