using like in join with code igniter active record

2019-05-24 16:29发布

问题:

I am having issues with a particular like in my active records query.

When I use join('users parent', 'child.treePath LIKE CONCAT(parent.treePath,"%")') Code igniter spits out JOIN 'users' parent ON 'child'.'treePath' 'LIKE' CONCAT(parent.treePath,"%") (note that I have replaced all back ticks (`) with (') due to markdown :/)

So, the issue is that code igniter is wrapping LIKE in (`).

How can I tell it to not attempt to format this block?


Complete query:

$this->db->select('child.uuid')
         ->from('users child')
         ->join('users parent', 'child.treePath LIKE CONCAT(parent.treePath,"%")')
         ->where('parent.uuid', $uuid)
         ->where("LENGTH(REPLACE(child.treePath, parent.treePath, '')) - LENGTH(REPLACE(REPLACE(child.treePath, parent.treePath, ''), '/', '')) <= ",  $levels, 'false')
         ->where("LENGTH(REPLACE(child.treePath, parent.treePath, '')) - LENGTH(REPLACE(REPLACE(child.treePath, parent.treePath, ''), '/', '')) > ",  0, 'false')
         ->group_by('child.treeId');

回答1:

If you are chaining all these functions together in a single call, you might as well just use

$this->db->query("Write all your specific SQL here");

Not seeing the benefit of wrestling with Codeigniter's query builder in your case.