title: How to nest WHERE params in Datamapper ORM for Codeigniter?
body: <p>I am having trouble with a specific query, using Datamapper ORM for Codeigniter. My data model is set up so that I have blog posts, each of which have many categories, users, and tags. I want to fetch blog posts that are related to a specific category, user, or tag, but is <strong>also</strong>  of status "published" or "scheduled."</p>
  
  <p>So in other words, what I want to accomplish is:
  <code>category = General AND (status = published OR status = scheduled)</code></p>
  
  <p>In Datamapper ORM I've tried the following syntax (assuming I want posts that are in the category with the name 'General'):</p>
  
  <pre><code>$posts-&gt;where_related('category', 'name', 'General')
        -&gt;where('status', 'published')
        -&gt;or_where('status', 'scheduled')
        -&gt;get();
  </code></pre>
  
  <p>However, this results in getting posts that are: <code>(status = published AND category = General) OR status = scheduled</code>.  Changing around the order of the statements doesn't help either. I can't seem to figure out if there's a Datamapper syntax for nesting the OR conditional in parentheses.</p>
  
  <p>I realize I could write the query in raw SQL, such as:</p>
  
  <p><code>SELECT * FROM posts WHERE (status = "published" OR status = "scheduled) AND ...</code></p>
  
  <p>...followed by some more complicated JOIN statements, but the whole reason I'm using Datamapper is to make working with relationships easier, so I don't think I should have to write this whole thing out in raw SQL just to nest an OR conditional! I also realize I could use subqueries, but again, I don't think it should be that complicated.</p>
  
  <p>Is there something I'm missing? Some way to organize this query so that I can accomplish it using Datamapper's syntax? It seems like being able to specify the order of operations of the AND/OR statements should be built in somehow...</p>