开发者

Cakephp SQL Error: 1064:

Have a find call on a table called Attachment which is assiciated with another table called AddOn. I get a sql error. It seems to be looking for a field called display_field but this is not in the table. Why it is looking for it I do not know.

$previous = $this->AddOn->Attachment->find('first', array('conditions'=> array('model'=>'AddOn', 'foreign_key'=>$id)));

Error:

SQL Error: 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 'display' at line 1 [CORE/cake/libs/model/datasources/dbo_source.php, line 684]

Query: display

Array
(
    [Attachment] => Array
        (
            [id] => 44
            [model] => AddOn
            [foreign_key] => 41
            [dirname] => img
            [basename] => fontgame_620x432.png
            [checksum] => 0488620c807cfaebb17489cb9c33f4fe
            [alternative] => Fontgame-620x432
            [group] => attachment
            [created] => 2011-09-22 14:04:35
            [modified] => 2011-09-22 14:04:35
            [file] => /home/t553788/public_html/res360/res/app/webroot/Media/transfer/img/fontgame_620x432.png
            [ratio] => 1.43518518519
            [known_ratio] => √2:1
            [megapixel] => 0
            [quality] => 1
            [width] => 620
            [height] => 432
            [bits] => 8
       开发者_运维百科     [size] => 176726
            [mime_type] => image/png
        )

    [AddOn] => Array
        (
            [id] => 41
            [add_on_category_id] => 6
            [title] => new addon
            [description] => qwedwed
            [enabled] => 0
            [list_no] => 0
            [availability] => 1
            [price_quote_as] => 0
            [price] => 10.00
            [valid_from] => 2011-09-01
            [valid_to] => 2011-09-02
            [created] => 2011-09-20 18:22:51
            [updated] => 2011-09-22 16:29:38
            [deleted] => 0
            [display_field] => *missing*
        )

)

Attachment model:

        <?php
        class Attachment extends AppModel {

            var $name = 'Attachment';

            var $actsAs = array('Containable');

        }
        ?>

Addon Model;

            <?php
            class AddOn extends AppModel {

                var $name = 'AddOn';

                var $actsAs = array('Containable');

                var $belongsTo = array(

                    'AddOnCategory' => array('className' => 'AddOnCategory')

                );

                var $hasMany = array(

                    'AddOnPurchase' => array('className' => 'AddOnPurchase'),
                    'AddOnRateroom' => array('className' => 'AddOnRateroom'),

                    'Attachment' => array(
                          'className' => 'Media.Attachment',
                          'foreignKey' => 'foreign_key',
                          'conditions' => array('Attachment.model' => 'AddOn'),
                          'dependent' => true
                          )
                );

                /*
                var $validate = array(
                    'file' => array('mimeType' => array('rule' => array('checkMimeType', false, array( 'image/jpeg', 'image/png'))))
                );*/

                // before find  
                function beforeFind($queryData){

                    if(!isset($queryData['conditions']['AddOn.deleted'])){
                        $queryData['conditions']['AddOn.deleted'] = 0;
                    } 

                    return $queryData;

                }


            }
            ?>


The SQL query being performed is: display

As you know, the SQL query you are looking for should start like: SELECT <something> FROM ...

This one clearly doesn't and that is what MySQL is trying to tell you.

Check you aren't calling a method called display() from any of your code:

$this->display(); // in models or behaviors
$this->Attachment->display(); // in controller, etc

CakePHP tends to do this when you call a missing method on a model.

A common culprit is thinking you have included a behavior by setting the model property $actAs when the correct property is actually called $actsAs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜