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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:03:09+00:00 2026-06-18T14:03:09+00:00

preamble: a few days ago I asked a question to solve a HABTM-filter, I’m

  • 0

preamble: a few days ago I asked a question to solve a HABTM-filter, I’m not able to do it even with tutorials, so “Obi Kwan Kenobi youre my only hope”.

What I want to achieve: Filtering Staff by GroupID which is used in StaffStaffgroup

I’m having the following tablelayout

  • staffs (a person can belong to many groups)
  • staff_staffgroups (HABTM-linking table)
  • staffgroups (has a groupname)

The variable $tmp gets me a working array, but the problem is that Staff is a child object of StaffStaffgroups. I could parse throu and reassemble a array, but this isnt a nice solution.
So I want to use the condition on Staff (see comented line) but then I get the error 1054 “column not found: 1054 Unknown column”. I tried to bind and unbind, but no result there.

$group_id = 2;
$tmp = $this->Staff->StaffStaffgroup->find('all',
        array('conditions' => array(
            'StaffStaffgroup.staffgroup_id' => $group_id,
            'Staff.isActive =' => "1",
            'Staff.last_name LIKE' => "%$name%",
            )
         )
);

debug($tmp);

//$tmpConditions['AND'][] = array('StaffStaffgroup.staffgroup_id' => $group_ids);

EDIT:

I tried it with conditions and containable behaviour, but unfortunatelly its not filtering anything at all

    $this->Staff->contain(array('StaffStaffgroup'));
    $this->paginate = array('StaffStaffgroup' =>array(
                                    array('conditions'  => array(
                                            'StaffStaffgroup.staffgroup_id' => '2'
                                        )
                                    )
                                )
    );
  • I added to all models: public $actsAs = array(‘Containable’);
  • I tried also with an inner join but no filtering there:

     $this->paginate = array( 
     'conditions' => array('StaffStaffgroup.staffgroup_id' => 2 ),
     'joins' => array(
        array(
            'alias' => 'StaffStaffgroup',
            'table' => 'staff_staffgroups',
            'type' => 'INNER',
            'conditions' => 'StaffGroup_id = StaffStaffgroup.staffgroup_id'
        )
     )
    

    );

  • 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-06-18T14:03:10+00:00Added an answer on June 18, 2026 at 2:03 pm

    You cannot use the Containable behavior for this. Checkout the sql dump, you will see that the query is done.

    I would do it in two steps

    From StaffStaffgroup get the staff ids that belongs to the group you want

    $staff_ids = $this->Staff->StaffStaffgroup->find(
        'all', 
        array(
            'conditions' => array('StaffStaffgroup.staffgroup_id' => $group_id, ),
            'recursive' => -1,
            'fields' => array('StaffStaffgroup.staff_id'),
        )
    );
    

    Then get all staff using the previous result

    $staffs = $this->Staff->find(
        'all', 
        array(
            'conditions' => array(
                'Staff.id' => $staff_ids, 
                'Staff.isActive =' => "1",
                'Staff.last_name LIKE' => "%$name%",
            ),
        )
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Preamble I'm asking this question because even though I've read through a lot of
Preamble: I'm Italian, sorry for my bad English. So this is the question: considering
Preamble; This is NOT a general I have a giant app with a leak
Preamble: I know, disabling warnings is not a good idea. Anyway, I have a
Preamble I've searched to see if I can find this question anywhere on here
The following may not qualify as a SO question; if it is out of
Preamble: This is very close to this question , and I have read this
PREAMBLE: this question is quite obsolete, it was written when the preferred Android dev
Preamble So, this question has already been answered, but as it was my first
PREAMBLE: the question is wildly obsolete. There's no more Google Checkout, no more Checkout

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.