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 6368677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:42:22+00:00 2026-05-25T00:42:22+00:00

I have an object $this->user which is of model User . This object is

  • 0

I have an object $this->user which is of model User. This object is populated by $this->Auth->user in my app controller like so:

$this->user = ClassRegistry::init('User');
$this->user->set($this->Auth->user);

Works like a charm. If I print_r out $this->user in my controller it gives me:

User Object ( [validate] => Array ( blah blah blah

A typical object. Now I have a Group model which belongs to a User, and users have many groups. These variables are properly set in the models. Now I want to find all Groups for this particular user who is logged in. So I tried this:

$groups = $this->user->Group->find('list', array('fields'=>array('id', 'group_name')))

The key is that I want to use $this->user to automatically filter the Group query based on the owner_id in $this->user. It makes sense to me that if I’ve got a specific object representing a user and I do a Group query based on that user … it should only return the relevant groups.

The problem is that $groups contains all of the entries in the Groups table, rather than obviously the ones I only want from the current user. I don’t see why I would need to add a "conditions"=>"user_id"=$this->Auth->user('id') parameter to the find function because I’ve already specified what user I’m using via the model chain.

Any ideas why this is not working? The sql statment it runs is simply a SELECT on Groups WHERE 1 = 1 (so not filtering at all).

  • 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-25T00:42:22+00:00Added an answer on May 25, 2026 at 12:42 am

    No, the object User really acts more like a class than a object. You can say Cake doesn’t fully implement Active Record pattern (I think Cake 3.0 may fix that, not sure). So yes, you still need to set the condition for the find. And you don’t have to set($this->Auth->user);

    You are probably not very familiar with Cake: in Cake, you hardly ever have to instantiate Model objects at all. They are created for you based on the current controller and model relationships that you specify.

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

Sidebar

Related Questions

I have a script which creates a user-defined object like this: obj = new
I have this object which is an instance of a superclass. I want to
In my qt app I have this object, filled before setting up my QTreeWidget's
I'm just wondering .. I have and object like this public class Entry{ public
I have a User model which has_many Documents. Each Document's title must be unique
I have a model which contains a ManyToMany to User to keep track of
So long story short I have an object model in which several different entity
So I have a model object, which is a named 'location' which has a
I have this test case def setUp(self): self.user = User.objects.create(username=tauri, password='gaul') def test_loginin_student_control_panel(self): c
I have this object graph, I want to map: abstract Account (username, password, ...)

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.