I'm calling the following query to retrieve records and the primary table data elements are all included, but the JOIN elements of data are not included. Any suggestions what I'm missing?
private function getRecordsOfMbrs($endDate)
{
$db = $this->getDatabase();
$query = $db->getQuery(true);
$query->select('a.*, b.title, b.term_type, b.term_dur, u.name, u.email');
$query->from($db->quoteName('#__mycomponent_records', 'a'));
$query->join('LEFT', $db->quoteName('#__mycomponent_rectypes', 'b') . ' ON ' . $db->quoteName('b.id') . ' = ' . (int) $db->quoteName('a.type_id'));
$query->join('LEFT', $db->quoteName('#__users', 'u') . ' ON ' . $db->quoteName('u.id') . ' = ' . (int) $db->quoteName('a.user_id'));
$query->where($db->quoteName('a.end_date') . ' = ' . $db->quote($endDate));
$query->where($db->quoteName('a.state') . ' = ' . (int) 2);
$db->setQuery($query);
try {
$recMbrs = $db->loadObjectList();
$this->logTask('Retrieved records for members.', 'notice');
return $recMbrs;
} catch (RuntimeException $e) {
$this->logTask($e->getMessage());
return Status::KNOCKOUT;
}
}
If I use this query in the database directly, all is returned as expected.
SELECT a.*, b.title, b.term_type, b.term_dur, u.name, u.email
FROM `uj2k9_mycomponent_records` a
LEFT JOIN `uj2k9_mycomponent_rectypes` b ON b.id = a.type_id
LEFT JOIN `uj2k9_users` u ON u.id = a.user_id
WHERE a.end_date = '2024-04-24'
AND a.state = 2
0
there? Surely you need to remove the(int)
casting, right? From what I see, every use of(int)
in your script is either unnecessary or actively doing harm. This is what is called a "footgun". To be honest, there is no part of your query building process that benefits from callingquoteName()
. I recommend removing all of these code bloating calls.