Welcome Guest, Not a member yet? Register   Sign In
Active Records and complex queries
#1

[eluser]Shella[/eluser]
Hi,
I'm using active records but I can't manage the bracket (parenthesis) when the query is composed.

My example is this.

Active record:

Code:
$this->db->select('*');
$this->db->where('friends.active', 1);
$this->db->where('friends.user_id', $user);
$this->db->or_where('friends.friend_id', $user);
$this->db->where('friends.active', 1);

and this is going to compose this:

Code:
SELECT * FROM (`friends`) WHERE `friends`.`active` = 1 AND `friends`.`user_id` = '8' OR `friends`.`friend_id` = '8' AND `friends`.`active` = 1

but the result I seek should be something like:

Code:
SELECT * FROM ( `friends` ) WHERE ( `friends`.`active` = 1 AND `friends`.`user_id` = '8' ) OR ( `friends`.`friend_id` = '8' AND `friends`.`active` = 1 )

..as you see the difference stand on the brackets.

The only workaround I found is to use directly $query = $this->db->query() with NOT implementing the Active Records.

Is this the only way? And Is this right in your opinion?


Messages In This Thread
Active Records and complex queries - by El Forum - 08-22-2012, 09:00 AM
Active Records and complex queries - by El Forum - 08-22-2012, 11:49 AM
Active Records and complex queries - by El Forum - 08-22-2012, 12:33 PM
Active Records and complex queries - by El Forum - 08-22-2012, 12:35 PM
Active Records and complex queries - by El Forum - 08-22-2012, 12:53 PM
Active Records and complex queries - by El Forum - 08-22-2012, 10:05 PM
Active Records and complex queries - by El Forum - 08-23-2012, 12:55 AM
Active Records and complex queries - by El Forum - 08-23-2012, 01:42 AM
Active Records and complex queries - by El Forum - 08-23-2012, 02:23 AM
Active Records and complex queries - by El Forum - 08-23-2012, 01:58 PM



Theme © iAndrew 2016 - Forum software by © MyBB