Welcome Guest, Not a member yet? Register   Sign In
Codeigniter AR and JOIN() with brackets?
#1

[eluser]_jon[/eluser]
I have a bunch of code that used to work in CI 1.6 but since the update, it has ceased to work. It appears that the brackets in this piece of code are being trimmed out:

Code:
$this->db->join('subscriptions', '(subscriptions.subscription_user_id = ' . $this->user->getId() . ' and subscriptions.subscription_thread_id = threads.thread_id)', 'left');

Is there any way I can stop this happening? I don't want to edit the base CI classes if at all possible... it's causing my queries to fail currently!
Thanks.
#2

[eluser]TheFuzzy0ne[/eluser]
Are you using $this->db->from()? If so, ensure $this->db->join() is in the code below it, not above it.

It would probably help more if you could post the entire query part of the function.
#3

[eluser]_jon[/eluser]
I am indeed using $this->db->from(). It is above the joins.

Refer to the current AR at: - here's a snippet from the join() function: http://dev.ellislab.com/svn/CodeIgniter/...ve_rec.php

Code:
// Strip apart the condition and protect the identifiers
if (preg_match('/([\w\.]+)([\W\s]+)(.+)/', $cond, $match))
{
     $match[1] = $this->_protect_identifiers($match[1]);
     $match[3] = $this->_protect_identifiers($match[3]);
        
     $cond = $match[1].$match[2].$match[3];        
}

Because my condition begins with a bracket, it's not matched by the regular expression, and so is cut out. The CLOSING bracket however, is (due to the .+ part of the regex). Introducing more of my query will probably over complicate things (its tens of lines long)... this -used- to work as the old AR (as far as I know) didn't have this preg_match block in the join function. So:

Code:
(subscriptions.subscription_user_id = ' . $this->user->getId() . ' and subscriptions.subscription_thread_id = threads.thread_id)

becomes

Code:
subscriptions.subscription_user_id = 1 and subscriptions.subscription_thread_id = threads.thread_id)

no good Sad
#4

[eluser]_jon[/eluser]
For now, I've reverted back to CodeIgniter 1.6.3, where the query works perfectly.




Theme © iAndrew 2016 - Forum software by © MyBB