Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7196895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:51:57+00:00 2026-05-28T20:51:57+00:00

I am having trouble with a specific query, using Datamapper ORM for Codeigniter. My

  • 0

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 also of status “published” or “scheduled.”

So in other words, what I want to accomplish is:
category = General AND (status = published OR status = scheduled)

In Datamapper ORM I’ve tried the following syntax (assuming I want posts that are in the category with the name ‘General’):

$posts->where_related('category', 'name', 'General')
      ->where('status', 'published')
      ->or_where('status', 'scheduled')
      ->get();

However, this results in getting posts that are: (status = published AND category = General) OR status = scheduled. 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.

I realize I could write the query in raw SQL, such as:

SELECT * FROM posts WHERE (status = "published" OR status = "scheduled) AND ...

…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.

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…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T20:51:58+00:00Added an answer on May 28, 2026 at 8:51 pm

    If you need parentheses for your where clauses, you need to add them.

    See http://datamapper.wanwizard.eu/pages/get.html#Query.Grouping for some examples.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get a query from a specific model. I'm having trouble getting
I am using a jqgrid but am having trouble positioning to a specific page.
I am having trouble with one specific query. It needs to run in a
I'm having trouble figuring out the SQL statement to retrieve a specific set of
I'm having trouble with my sqlite database. I'm trying to write an query that
I'm having trouble with a certain mapping. Let's say I have three assessments that
I'm having some trouble computing specific days relative to the current date using NSDate
I am having trouble with a function that checks if a set of user
I'm having trouble with a shell script in Cygwin. The specific command that's causing
To start off, this really isn't CodeIgniter specific. I'm having trouble grasping an idea,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.