简体   繁体   English

CodeIgniter DataMapper ORM include_related始终返回数据库表中的第一行

[英]CodeIgniter DataMapper ORM include_related always returning first row in database table

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. 我有一个用户模型和一个user_profile模型,并且尝试通过以下功能获取特定用户和相关的user_profile。 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 in the database and not the user based on user_id. 如果我注释掉include_related行,它将起作用并基于user_id获取用户,但是如果我尝试使用include_related来拉入用户个人资料字段,则它只会返回数据库中的第一个用户,而不是基于user_id的用户。 Whats going wrong here? 怎么了

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

Was having a mental block it 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();

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

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