1

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;

                }


            }
            ?>

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

4 Comments

I have added the models. The relationship between them is one belongs to one but I could not get it to work, it conplained about the foreign key in the sql statement
I have gone over the models and controllers and cant see the issue or why it is looking for a display_field in the addon table
What leads you to believe it is looking for a field called display_field? The SQL error would state SQL Error (1054): Unknown column 'display_field' in 'field list' if this was the case. I still think there is a method call to a missing display() method in your code somewhere.
I searched through it and cannot see any display() call. In the array I posted above if you look at the last entry you see [display_field] => missing. There is no display_field in the code or the database. I agree there has to be something in the code but where and what. Do you see any issue with the code I posted?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.