问题描述
|
我在活动记录查询中遇到了特定问题。
当我使用
join(\'users parent\',\'child.treePath LIKE CONCAT(parent.treePath,\"%\")\')
时
代码点火器吐出JOIN \'users\' parent ON \'child\'.\'treePath\' \'LIKE\' CONCAT(parent.treePath,\"%\")
(注意,由于降价,我用(\'
)替换了所有的背tick(`
):/)
因此,问题在于代码点火器将LIKE包装在(`
)中。
我如何告诉它不要尝试格式化此块?
完整查询:
$this->db->select(\'child.uuid\')
->from(\'users child\')
->join(\'users parent\',\"%\")\')
->where(\'parent.uuid\',$uuid)
->where(\"LENGTH(REPLACE(child.treePath,parent.treePath,\'\')) - LENGTH(REPLACE(REPLACE(child.treePath,\'\'),\'/\',\'\')) <= \",$levels,\'false\')
->where(\"LENGTH(REPLACE(child.treePath,\'\')) > \",\'false\')
->group_by(\'child.treeId\');
解决方法
如果您要在一次调用中将所有这些功能链接在一起,则最好使用
$this->db->query(\"Write all your specific SQL here\");
在您的情况下,没有看到与Codeigniter的查询生成器进行搏斗的好处。