Welcome Guest, Not a member yet? Register   Sign In
Query builder question (CI 4 newbie)
#1

Hi there
I started making my first steps with CI4 after years of experience with CI. Now I'm struggling with something that worked fine with query builder prior to CI4.
Here are two functions of a basic model:
PHP Code:
public function getThread($id$field NULL) {

 
$query $this->db->table('threads')
              ->where('id'$id)
              ->get();

 
$thread $query->getRow();

 if (
$thread == FALSE) {

    return FALSE;
 }

 
$thread->posts $this->basicModel->getPostsByThread($thread->id);

 if (
is_null($field)) {

    return $thread;
 }

 else {

    return $thread->$field;
 } 
 }


 public function 
getPostsByThread($thread_id) {

 
$query $this->db->table('posts')
              ->where('thread_id'$thread_id)
              ->orderBy('date')
              ->get();

 return 
$query->getResult();
 } 

So, when calling function getThread() CI4 return the following error caused by the line $thread->posts = …:


Quote:CodeIgniter\Database\Exceptions\DatabaseException #8
You must set the database table to be used with your query.

I guess I have to rethink using query builder. Maybe you can give me a hint.
Reply


Messages In This Thread
Query builder question (CI 4 newbie) - by bastian - 07-27-2021, 02:18 AM



Theme © iAndrew 2016 - Forum software by © MyBB