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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:12:07+00:00 2026-06-13T23:12:07+00:00

I cannot get the associated Model data using hasMany through (Join Model) association. I’m

  • 0

I cannot get the associated Model data using hasMany through (Join Model) association.
I’m working with cakephp 2.2.3
The same find were ok in cakephp 1.3, so i don’t know what’s the matter…

Event hasMany ScoresToEvent.
Scores hasMany ScoresToEvent.
ScoresToEvent belongsTo Event and Score.

ScoresToEvent will have additional info, so i cannot use HATBM.

some code:

event.php    
class Event extends AppModel{
      public $name='Event';
      public $hasMany=array('ScoresToEvent');
      public $belongsTo=array('Entity');
      public $actsAs=array('containable');
} 

score.php
class Score extends AppModel{
      public $name='Score';
      public $hasMany=array('ScoresToEvent');
      public $belongsTo=array('Entity');
}

scores_to_event.php
class ScoresToEvent extends AppModel{
   public $name='ScoresToEvent';
   public $belongsTo=array('Event','Score');
}

When i retrieve data i get these results:

$this->Event->ScoresToEvent->find('all', array('recursive'=>2))
array(
    (int) 0 => array(
        'ScoresToEvent' => array(
            'id' => '8',
            'event_id' => '7',
            'score_id' => '1'
        )
    ),
    (int) 1 => array(
        'ScoresToEvent' => array(
            'id' => '9',
            'event_id' => '7',
            'score_id' => '3'
        )
    )
) 

In this case i have to get Event and Score data.

If I try to use containable it returns that Model “ScoresToEvent” is not associated with model “Score” and this array, consequently it doesn’t retrieve the Score data…

$this->Event->find('all', array(
      'contain'=>array(
         'Entity',
         'ScoresToEvent'=>array('Score'=>array('Entity'))
      ),
      'conditions'=>array('Event.id'=>7));

array(
    (int) 0 => array(
        'Event' => array(
            'id' => '7',
            'entity_id' => '17',
            'start_date' => '2012-07-24',
            'status' => null,
            'end_date' => null
        ),
        'Entity' => array(
            'id' => '17',
            'title' => 'y',
            'content' => '',
            'subtitle' => '',
            'type' => 'Evento',
            'avatar' => null,
            'image' => null
        ),
        'ScoresToEvent' => array(
            (int) 0 => array(
                'id' => '8',
                'event_id' => '7',
                'score_id' => '1'
            ),
            (int) 1 => array(
                'id' => '9',
                'event_id' => '7',
                'score_id' => '3'
            )
        )
    )
)

Where is my fault? what part of code is wrong?
I tried this on a brand new cakephp 2.2.3 installation

Thanks all

p.s. The same code works correctly in cakephp 1.3
p.p.s. do not consider ‘Entity’.

  • 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-13T23:12:07+00:00Added an answer on June 13, 2026 at 11:12 pm

    I think is a problem of name of the model. Try to rename the file scores_to_event.php to ScoresToEvent.php.
    But in this case I think that the bestname ofr this model is: ScoreEvent.php, is more appropriate.
    After try to insert more information to your model like this example:
    into ScoreEvent.php

    public $belongsTo = array(
            'Event' => array(
                'className'    => 'Event',
                'foreignKey'   => 'event_id'
            ),
           'Score' => array(
                'className'    => 'Score',
                'foreignKey'   => 'score_id'
            )
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I cannot get my Spring web app to find my scripts. I have the
I cannot get my SID working ... <?php session_start(); // Or maybe pass along
I cannot get my Wordpress theme to randomise the posts I'm displaying in the
I cannot get this function to fire off... I'm thinking I need a fresh
I cannot get Bindable LINQ to work with VB.NET for the life of me.
I cannot get the background to stretch behind the contentbox. The strange thing is,
I cannot get the jQuery slideDown function to work on <table> elements. They just
I cannot get the DropDownHeight of the ComboBox set properly to display all the
I cannot get the example Python programs to run. When executing the Python command
I cannot get the following route to fire when a url is requested from

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.