DirtyBirdNJ
DirtyBirdNJ

Reputation: 592

CakePHP 2.4.2 Why is Cake using model names as SQL queries?

I have a fresh out o' the git repo CakePHP application. I just made a new model (Ingests) to track what data our system brings in. I wanted to make functions start() and end(), but end is protected so I switched to begin() and finish().

No matter what I do, CakePHP is trying to execute the model function names verbatim as the SQL queries. I have another model in this app that I've been working on this week that has not had this issue at all. Creating a new table/model today is when the problem appeared.

IngestsController.php

public function test(){


    $this->autoRender = false;

    //$result = $this->Ingest->finish();
    $result = $this->Ingest->xyz();

    debug($result);

}

Ingests.php Model

public function finish($id){

    return 'giraffe';

}

public function xyz(){

    return 'abc';

}

Output:

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 'xyz' at line 1

SQL Query: xyz

I tried xyz() because there is no way xyz() could be a protected/not allowed function name... but apparently it's just as bad a choice as finish(). If I run the finish() function, I get the same output... "SQL Query: finish"

Upvotes: 0

Views: 309

Answers (1)

vicocamacho
vicocamacho

Reputation: 178

Check your file name, the name for your file name model should be Ingest.php instead of Ingests.php also check your class declaration:

<?php
App::uses('AppModel', 'Model');

class Ingest extends AppModel { //Make sure the model name is singular

    public function finish($id){

        return 'giraffe';

    }

    public function xyz(){

        return 'abc';

    }
}

Upvotes: 2

Related Questions