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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:38:53+00:00 2026-06-04T17:38:53+00:00

I’m having a strange issue with a CakePHP 2.1.1 Project. The issue is that

  • 0

I’m having a strange issue with a CakePHP 2.1.1 Project.
The issue is that if I call a find() on the Competition model (in the following code), right after it I call a custom method in another model the operation fails with the following error:

Error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'getAddedPlayersIds' at line 1

SQL Query: getAddedPlayersIds 

My CompetitionsController::view() code is as follows:

public function view($id = null) {
        $this->layout = 'competition';
        $this->Competition->id = $id;
        if (!$this->Competition->exists()) {
            throw new NotFoundException(__('Invalid competition'));
        }

        $active = $this->Competition->field('active', array('id' => $id));
        if (!$active) {
        $this->redirect(array('controller' => 'pages', 'action' => 'display', 'competition_inactive'));
        }
            //THIS IS WHERE IT BECOMES STRANGE:
        $competition = $this->Competition->find('first', array('conditions' => array('Competition.id' => $id)));

        $addedPlayersIds = $this->CompetitionsPlayer->getAddedPlayersIds($id);

            //SOME CODE INTENTIONALLY REMOVED HERE!!!       

        $this->set('playerShops', $playerShops);    
        $this->set('messages', $messages);
        $this->set('competition', $this->Competition->read(null, $id));
            //render() IS CALLED FOR A SPECIFIC REASON
        $this->render();
    }

This is what the CompetitionsPlayer::getAddedPlayersIds() method looks like:

public function getAddedPlayersIds($competitionId = null){
        if(!isset($competitionId)) {
            return false;
        }

        $this->displayField = 'player_id';
        return $this->find('list', array('conditions' => array('competition_id' => $competitionId)));
    }

I initially thought that it’s somehow breaking, because of the variable name I’m assigning the return of the Model::find() operation to, which is ‘competition’, but what’s more interesting is that if I move the Competition::find() call after the CompetitionsPlayer::getAddedPlayersIds() it works!
Furthermore if I rename the variable it will sometimes work, and sometimes not…!?
I still can’t figure out which is when because I currently have no time to research this further.
Notice that according to the debug information the query that gets executed over the database is:

getAddedPlayersIds

which is the name of the function I’m calling!

As I mentioned I already know the workaround for this – just swap the two calls.But what if the first was to be before the seconds and there was no other way to implement the task at hand??
All I want now is to know why this happens?

  • 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-04T17:38:55+00:00Added an answer on June 4, 2026 at 5:38 pm

    It turns out that when using Model::field() the function’s implementation sets recursive to -1 or 0. The CakePHP core code is:

    public function field($name, $conditions = null, $order = null) {
    //Some code ommited
        if ($this->recursive >= 1) {
            $recursive = -1;
        } else {
            $recursive = $this->recursive;
        }
    //Some code ommited
    }
    

    So as explained this is the issue. I understand that this is a performance optimization, but I am not sure if this is a feature or a problem. To me this is strange behavior.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.