• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SubQuery Not Working

#1
I have the following function that uses a subquery and this error pops up

Code:
TypeError
Argument 1 passed to App\Models\MainModel::App\Models\{closure}() must be an instance of App\Models\BaseBuilder,
instance of CodeIgniter\Database\MySQLi\Builder given, called in C:\CI_system_4A\Database\BaseBuilder.php on line 970

PHP Code:
//-----------------------------------------------
function get_current_subjects()
    {
        $db = \Config\Database::connect();
        $builder $db->table('central.v1_cal_subjects');
        $builder $builder->distinct()->select("subject_code,subject_name");
        $builder $builder->whereIn("cal_id", function(BaseBuilder $builder)   [u][color=#e82a1f]// error on this line[/color][/u]
                                                {
                                                    return $builder->select("cal_id")->from('central.v1_calendar')->where('`year` >= year(now())'null,false); 
                                                }
                                      );
        $builder $builder->orderby("subject_code");
        $query $builder->get();
        return $query->getResultArray();
    



I used the example for the Online reference as a guide

Quote:$builder->whereIn('id', function(BaseBuilder $builder) {
    return $builder->select('job_id')->from('users_jobs')->where('user_id', 3);
});
// Produces: WHERE "id" IN (SELECT "job_id" FROM "users_jobs" WHERE "user_id" = 3)



An ideas on whats wrong with my code?
Thanx
Reply

#2
No answers yet!

My debugging leads me to think that the issue is actually with the CI4 System framework itself. It appears not to be building the subquery at all, before it hands the result back from the anonymous function call [function(BaseBuilder $builder)].

I have given up on subqueries an just using the SQL code below

$sql = "SELECT DISTINCT subject_code,subject_name
FROM central.v1_cal_subjects
WHERE cal_id IN (SELECT cal_id FROM central.v1_calendar WHERE `year` >= YEAR(NOW()))
ORDER BY subject_code";
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.