Hailwood
Hailwood

Reputation: 92581

using like in join with code igniter active records

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');

Upvotes: 2

Views: 1948

Answers (1)

jondavidjohn
jondavidjohn

Reputation: 62392

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.

Upvotes: 3

Related Questions