• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Codeigniter AR and JOIN() with brackets?

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:

$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!

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.

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

// 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:

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


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

no good Sad

For now, I've reverted back to CodeIgniter 1.6.3, where the query works perfectly.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.