title: Laravel Eloquent whereRaw sql clause returns all rows when using OR operator
body: <p>In <a href="http://laravel.com/" rel="nofollow">Laravel</a> i am using <a href="http://laravel.com/docs/4.2/eloquent" rel="nofollow">Eloquent ORM</a> to fetch all users associated with a group.</p>
  
  <p>(It's a legacy database so it doesn't follow Laravel conventions unfortunately).</p>
  
  <p>The users table has a column with a GroupId which is a Foreign Key to a Group table with the associated information on the group which the users belongs to.</p>
  
  <p>I want to select all users associated with two specific groups, selected by their name. And it works when i DO NOT use an OR operator in the whereRaw clause of the SQL statement. In that case it just returns all rows, despite their names.</p>
  
  <p>If i remove the OR ..., the code works as intended and returns only users associated with the GroupId i query, in this case "KO011". </p>
  
  <p>('GroupId's semantic meaning is just the Groups name)</p>
  
  <pre><code>User::select(array('name','surname','GroupId'))-&gt;with(array('Group'=&gt; function($q)
      {
          $q-&gt;select(array('Id','GroupId', 'GroupDescription'));
  
      }))-&gt;whereHas('Group', function($q)
      {
          $q-&gt;whereRaw("GroupId = 'KO11' OR GroupId = 'KO05'");
      })-&gt;get());
  </code></pre>
  
  <p>The sql log dump from when i query with the or operator is (undesired result, all rows):</p>
  
  <pre><code>[2014-11-28 17:12:40] local.INFO: select `name`, `surname`, `GroupId` from `Users` where (select count(*) from `Group` where `Users`.`GroupId` = `Group`.`Id` and GroupdId = 'KO11' or GroupId = 'KO05') &gt;= 1 {"bindings":[],"time":182.84,"name":"dbname"} []
  [2014-11-28 17:12:40] local.INFO: select `Id`, `GroupId`, `GroupDescription` from `Group` where `Group`.`Id` in (0, 12, 28, 9, 3, 32, 4, 2, 1, 16, 31, 13, 18, 10, 33, 29, 5, 11, 8, 21, 19, 20, 14, 30, 25, 22, 6, 23, 7, 15, 48, 17, 26, 24, 157, 52, 27, 51, 47, 50, 158, 134, 104, 105, 106, 118, 154, 103, 96, 107, 101, 108, 146, 102, 109, 100, 98, 99, 97, 95, 174, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 149, 183, 110, 184, 170, 111, 150, 114, 138, 113, 112, 159, 145, 121, 115, 140, 176, 117, 147, 135, 116, 139, 155, 148, 169, 164, 165, 166, 161, 185, 168, 172, 177, 167, 178, 180, 179, 191, 173, 193, 188, 175, 192, 187) {"bindings":[0,12,28,9,3,32,4,2,1,16,31,13,18,10,33,29,5,11,8,21,19,20,14,30,25,22,6,23,7,15,48,17,26,24,157,52,27,51,47,50,158,134,104,105,106,118,154,103,96,107,101,108,146,102,109,100,98,99,97,95,174,94,93,92,91,90,89,88,87,86,85,84,149,183,110,184,170,111,150,114,138,113,112,159,145,121,115,140,176,117,147,135,116,139,155,148,169,164,165,166,161,185,168,172,177,167,178,180,179,191,173,193,188,175,192,187],"time":55.44,"name":"dbname"} []
  </code></pre>
  
  <p>and when i only query with one group (correct results):</p>
  
  <pre><code>[2014-11-28 17:57:26] local.INFO: select `name`, `surname`, `GroupId` from `Users` where (select count(*) from `Group` where `Users`.`GroupId` = `Group`.`Id` and GroupId = 'KO11') &gt;= 1 {"bindings":[],"time":93.18,"name":"dbname"} []
  [2014-11-28 17:57:26] local.INFO: select `Id`, `GroupId`, `GroupDescription` from `Group` where `Group`.`Id` in (3) {"bindings":[3],"time":405.02,"name":"dbname"} []
  </code></pre>