simbolo
Well-known member
Looking through the model files in a lot there is declaring of const for the table that will be joined on later.
E.G. in /library/XenForo/Model/Thread.php
Then later on before joining on that table there's a check to make sure the const is defined.
My question is: what is it's purpose?
Better put,
Why does it allow joins on other tables?
Is there a pattern that should be followed for naming and the value assigned to them?
E.G. in /library/XenForo/Model/Thread.php
PHP:
class XenForo_Model_Thread extends XenForo_Model
{
/**
* Constants to allow joins to extra tables in certain queries
*
* @var integer Join user table
* @var integer Join node table
* @var integer Join post table
* @var integer Join user table to fetch avatar info of first poster
* @var integer Join forum table to fetch forum options
*/
const FETCH_USER = 0x01;
const FETCH_FORUM = 0x02;
const FETCH_FIRSTPOST = 0x04;
const FETCH_AVATAR = 0x08;
const FETCH_DELETION_LOG = 0x10;
const FETCH_FORUM_OPTIONS = 0x20;
>>>>>
}
Then later on before joining on that table there's a check to make sure the const is defined.
PHP:
if (!empty($fetchOptions['join']))
{
if ($fetchOptions['join'] & self::FETCH_USER)
{
$selectFields .= ',
user.*, IF(user.username IS NULL, thread.username, user.username) AS username';
$joinTables .= '
LEFT JOIN xf_user AS user ON
(user.user_id = thread.user_id)';
}
Better put,
Why does it allow joins on other tables?
Is there a pattern that should be followed for naming and the value assigned to them?