2012-03-21 4 views
1

私はユーザーモデルとuser_profileモデルを持っていますが、以下の関数で特定のユーザーと関連するuser_profileを取得しようとしています。 include_related行をコメントアウトすると、user_idに基づいてユーザーが取得されますが、include_relatedを使用してユーザープロファイルフィールドを取得しようとすると、user_idに基づいてユーザーではなくデータベースの最初のユーザーが返されます。何がここで間違っている?CodeIgniter DataMapper ORM include_relatedは常にデータベーステーブルの最初の行を返します

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

答えて

0

は、それがされている必要があり精神的なブロックを持っていた:

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