Welcome Guest, Not a member yet? Register   Sign In
Model relationships
#2

[eluser]darkhouse[/eluser]
Just because you have a users model and a comments model doesn't mean you can't return user data from the comments model.

I would do this:
Code:
class Comments_model extends Model {
   function getComments($entry_id){
      $this->db->select('c.comment, u.username'); //or whatever you're selecting
      $this->db->join('users u', 'c.user_id = u.id');
      $this->db->where('c.entry_id', $entry_id);
      $query = $this->db->get('comments c');
      return $query->result();
   }
}

Now you can do things like you normally would, and like you should.


Messages In This Thread
Model relationships - by El Forum - 01-13-2009, 06:24 PM
Model relationships - by El Forum - 01-13-2009, 10:52 PM
Model relationships - by El Forum - 01-13-2009, 11:06 PM
Model relationships - by El Forum - 01-14-2009, 02:44 AM
Model relationships - by El Forum - 01-14-2009, 04:30 AM
Model relationships - by El Forum - 01-14-2009, 05:36 AM
Model relationships - by El Forum - 01-14-2009, 06:11 AM
Model relationships - by El Forum - 01-14-2009, 06:31 AM
Model relationships - by El Forum - 01-14-2009, 08:23 AM
Model relationships - by El Forum - 01-15-2009, 12:55 PM



Theme © iAndrew 2016 - Forum software by © MyBB