ThingEngineer / PHP-MySQLi-Database-Class

Wrapper for a PHP MySQL class, which utilizes MySQLi and prepared statements.
Other
3.3k stars 1.34k forks source link

DbObject Paginate to retrieve fields from joined tables #833

Open xeon826 opened 5 years ago

xeon826 commented 5 years ago

Is it possible to tell paginate to retrieve columns from joined tables? I could return the whole thing but if I could tell it to only retrieve the columns I want it would save writing a lot of JS This is my query

        $schedulesJson = Schedule::JsonBuilder()->with('customer')->with('user')->where('tblschedules.owner_id', $user->owner_id);
        Schedule::$pageLimit = $request['num_results'];
// I return $schedulesJson from the repository to my controller where it's named $schedules
        $schedules = $schedules->paginate(1, ['shift_date', 'shift_start', 'shift_end', 'customer_name', 'user_displayname']);

` I've tried 'tblcustomers.customer_name', 'customer[customer_name]', 'customer.customer_name', and 'tblcustomers.customer_name' Then I try to paginate and retrieve columns from the joined tables, I get the columns that are in the base table (schedules) but not the joined tables. I'm aware I can just forego the second parameter but I'd like to just retrieve the ones I want.

xeon826 commented 5 years ago

So for some reason if I use Mysqlidb rawQuery to do the same exact query, it returns, I'm not sure why I'm unable to select values from joined tables when using DbObject.