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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:42:55+00:00 2026-05-19T23:42:55+00:00

Problem in short: I want to set conditions on an associated model. How do

  • 0

Problem in short: I want to set
conditions on an associated model. How
do I do it?

I’m having a problem with the associations in my CakePHP application.

The associations looks like this:

Event has many EventSum belongs to Account has many AccountUser belongs to User
Event has many EventDebt ... (the rest is the same as above)
Event also belongs to User

The application is a private econonmy program in PHP and uses the CakePHP framework.

An Event is a financial event, a purchase, transaction between accounts etc. It only holds information about date, title and user.

An EventSum holds information about an Account and how much to debit or credit (in one column, just positive or negative).

Account holds information about title of the account.

AccountUser holds an id of an Account and a User. This indicates that


So, now I want to fetch Events based on what accounts a User is associated to. How can I do this?

I want to fetch the following info:
Event, together with the EventSum. The Events are fetched from Accounts where the User has access.

Thanks for any help,
/Magnus

  • 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-19T23:42:56+00:00Added an answer on May 19, 2026 at 11:42 pm

    It seems like you want to be able to query your Event class with the following conditions:

    'Account.user_id =' => $userId
    

    Is my assumption correct?

    When doing queries which require conditions on associated models, you can use either the Containable behaviour (comes with CakePHP 1.3) or the ‘Linkable’ behaviour (which can be found here).

    What happens when you try this (be sure to attach the Containable behaviour to your models first):

    $condition = array('Account.user_id =' => $userId);
    $contain = array('EventSum' => array('Account'), 'EventDebt' => array('Account'));
    $result = $this->Event->find('all', compact('condition', 'contain'));
    

    Note that you might experience issues when ‘containing’ both EventSum and EventDebt if both of their associations to Account use the same alias name.

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

Sidebar

Related Questions

SHORT DESCRIPTION OF PROBLEM: I want to set the text of a searchbar without
I'm having the exact opposite problem of this post - specifically, I want to
I'm having a problem with this really short piece of code which I cannot
Following problem: I want to render a news stream of short messages based on
The problem I'm having is that I want to use STL's sort with a
So the wonderful low down on this doozie of a problem: short version: We
I want to use the MaskedEditExtender to mask short dates. The problem is that
I have the following problem... I want to set a session variable when clicking
This problem has bugged me for years, and I always feel like I'm coming
I want to do email confirmation, after having set up sign in/sign up and

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.