php - Function name is used as SQL query -
i've got problem similar ones found here , here, these solutions aren't helping me fix version of problem. i'm using cakephp 1.3 , i'm trying call model functions within view controller:
//class setup var $uses = array('studentstelephone', 'addressesstudent'); //... function somefunction(){ $this->set('telephones', $this->studentstelephone->getactivestudenttelepone($id)); $this->set('addresses', $this->addressesstudent->getactivebystudentid($id)); }
this first of model function calls (studentstelephone) works, second (addressesstudent) fails. attempts use function name sql call resulting in:
sql error: 1064: have error in sql syntax; check manual corresponds mysql server version right syntax use near 'getactivebystudentid' @ line 1 [core\cake\libs\model\datasources\dbo_source.php, line 684]
using little bit of debugging, find out function being looked in appmodel , addressesstudent never checked. based on other solutions looks should typo in name. however, appears correctly named. above code stated, model file addresses_student.php
, class name addressesstudent , working fine before updated cake (just switched 1.1 1.3). suggestions might causing problem not naming error? or maybe other naming error i'm missing? thank much!
edit: also, here's backtrace telling me model php file never found:
dbosource::showquery() - core\cake\libs\model\datasources\dbo_source.php, line 684 dbosource::execute() - core\cake\libs\model\datasources\dbo_source.php, line 266 dbosource::fetchall() - core\cake\libs\model\datasources\dbo_source.php, line 410 dbosource::query() - core\cake\libs\model\datasources\dbo_source.php, line 364 model::call__() - core\cake\libs\model\model.php, line 502 overloadable::__call() - core\cake\libs\overloadable_php5.php, line 50 appmodel::getactivebystudentid() - [internal], line ?? studentscontroller::edit() - app\controllers\students_controller.php, line 277 dispatcher::_invoke() - core\cake\dispatcher.php, line 204 dispatcher::dispatch() - core\cake\dispatcher.php, line 171 [main] - app\webroot\index.php, line 83
cakephp uses 'cached' auto-generated model
for habtm relations, cakephp automatically generate 'generic' model join-table (by creating instance appmodel) even if model exists join-table (don't ask me why!)
cakephp stores auto-generated model in cache can reused in other locations.
in example, try use addressesstudent
model. cakephp model name, , finds model name inside cache. this is, auto-generated model habtm relation, not actual model!
tell cakephp use your model , not auto-generated model
to prevent cakephp auto-generating model habtm relations, add with
option relations; sure specify @ both sides of relation (if defined @ both sides, is)
inside student model;
$public hasandbelongstomany = array( 'address' => array( // tell cakephp use addressesstudent model, // not , auto-generated model 'with' => 'addressesstudent', ), );
and/or inside address model;
$public hasandbelongstomany = array( 'student' => array( 'with' => 'addressesstudent', ), );
by doing this, you're preventing cache contains auto-generated models.;
with: defines name of model join table. default cakephp auto-create model you. using example above called recipestag. using key can override default name. join table model can used “regular” model access join table directly.
more information; hasandbelongstomany (habtm)
Comments
Post a Comment