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

  • SEARCH
  • Home
  • 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 6783943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:55:53+00:00 2026-05-26T16:55:53+00:00

I got a little problem with datamapper, and I’d like to know if there

  • 0

I got a little problem with datamapper, and I’d like to know if there is a quick solution.
Let’s say I have this kind of data

Groups table

id   |   Name
1    |   admin
2    |   guest
3    |   editor
4    |   moderator

In my base controller I set a global field to see only the groups that are not admin

$this->groups_ = new Group();
$this->groups_->where('id >', 1)->get();

//so I can select the users that are not admin
$users = new User();
$users->where_related('group',$id,$this->groups_)->get();

Now in my controllers I’d like to filter the groups. For example I want to select only editors and guests (id between 1 and 4). So I would like to filter the initial result set… something like this

$this->groups_->where('id <',4)->get();

But it doesn’t work. It returns ALL the group ids < 4 including admin.
What would be the right way to get this?

  • 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-26T16:55:54+00:00Added an answer on May 26, 2026 at 4:55 pm

    A possible solution

    Maybe I found a possible workaround by cloning the datamapper object.
    What I want to do is not to query the db multiple times, but I’d like to have a base resultset and refine the results.

    So in my base controller I would do something like

    $this->groups_ = new Group();
    $this->groups_->where('id >', 1);//without getting the results
    
    //so I can select the users that are not admin
    $users = new User();
    //here i'm getting the results from the clone
    $users->where_related('group',$id,$this->groups_->get_clone()->get())->get();
    

    And, as I left the object “open”, without getting the results, I can use it in my controllers, as a base for my other “queries”… ok,they are actually new conditions of the first query.

    //now the query return the groups between 2, as I set in the base controller
    //and 4, set in the child controller
    $this->groups_->where('id <',4)->get();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I still have a little problem grasping the concept of pure OOD. Let's say
I've got this little problem. When I have a string 3 568 030 and
I've got a little problem on a goDaddy server. I have a php script
I've got a little problem: I don't know whether it is possible to select
I have got a little problem using the CodeIgniter route function. I use the
I have got a little problem with repositioning a div that should serve as
I have a little math problem. I would like to have a function with
I've got a little problem: In my table I have these rows: PersHist :
I have got a little problem. I got a bxslider running on a website
I have got a little problem in IE8 with the nivoslider script and i

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.