Fixed Relation TO_ONE doesnt work well when multiple value is set in conditions

TickTackk

Well-known member
Affected version
2.0.x
In extended entity:
PHP:
        $structure->relations['Report'] = [
            'entity' => 'XF:Report',
            'type' => self::TO_ONE,
            'conditions' => [
                ['content_type', '=', '$content_type'],
                ['content_id', '=', '$content_id'],
                ['report_state', '=', ['open', 'assigned']]
            ],
            'primary' => true
        ];

under
PHP:
public static function getStructure(Structure $structure)

Generated query will have something like this:

SQL:
ON (`xf_report_Report_1`.`content_type` = `xf_approval_queue`.`content_type` AND `xf_report_Report_1`.`content_id` = `xf_approval_queue`.`content_id` AND `xf_report_Report_1`.`report_state` = 'open', 'assigned')

Fix (not 100% sure):

Find:
PHP:
                    else if (is_string($value) && $value && $value[0] == '$')
                    {
                        $value = "`$joinTable`.`" . substr($value, 1) . '`';
                    }
                    else
                    {
                        $value = $this->db->quote($value);
                    }

Replace with:
PHP:
                    else if (is_string($value) && $value && $value[0] == '$')
                    {
                        $value = "`$joinTable`.`" . substr($value, 1) . '`';
                    }
                    else if (is_array($value))
                    {
                        $value = '(' . $this->db->quote($value) . ')'; 
                        $operator = 'IN';
                    }
                    else
                    {
                        $value = $this->db->quote($value);
                    }

In file: src\XF\Mvc\Entity\Finder.php
 
Last edited:
Thank you for reporting this issue. It has now been resolved and we are aiming to include it in a future XF release (2.1.0 RC2).

Change log:
Allow arrays as the third value in relation join definitions to be mapped to <NOT> IN (a, b, c).
Any changes made as a result of this issue being resolved may not be rolled out here until later.
 
Top Bottom