4

I have one model Portfolio in which I have define join like

public $belongsTo = array(
        'Category' => array(
            'className' => 'Category',
            'foreignKey' => 'category_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        )
    );

now when I am using code in controller like:

$this->Portfolio->recursive = 0;
        $this->paginate = array(
            'fields' => array('Portfolio.id', 'Portfolio.application_name','Portfolio.category_id','Portfolio.description','Portfolio.screenshots','Portfolio.icon','Portfolio.bg_color_code','Portfolio.created','Category.title','Category.id'),
            'limit' => 10,
            'order' => array(
                'Portfolio.id' => 'asc'
            )
        );

so its working fine on my window 7 but its giving me error on linux server like:

Database Error

Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Category.title' in 'field list'

SQL Query: SELECT `Portfolio`.`id`, `Portfolio`.`application_name`, `Portfolio`.`category_id`, `Portfolio`.`description`, `Portfolio`.`screenshots`, `Portfolio`.`icon`, `Portfolio`.`bg_color_code`, `Portfolio`.`created`, `Category`.`title`, `Category`.`id` FROM `portfolios` AS `Portfolio` WHERE 1 = 1 ORDER BY `Portfolio`.`id` asc LIMIT 10

Notice: If you want to customize this error message, create app/View/Errors/pdo_error.ctp

and my category model contains

var $hasMany = array(
        'Portfolio' => array(
            'className' => 'Portfolio',
            'foreignKey' => 'category_id',
        )

    );

my table

CREATE TABLE IF NOT EXISTS `categories` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(255) NOT NULL,
  `parent_id` int(11) NOT NULL DEFAULT '0',
  `status` enum('1','2') NOT NULL COMMENT '''1''=active,''2''=inactive',
  PRIMARY KEY (`id`)
) 

I have tested in debug result its showing

Included Files
Include Paths
    0/home/reviewpr/public_html/imobdevnew/lib
    2/usr/lib/php
    3/usr/local/lib/php
    4-> /home/reviewpr/public_html/imobdevnew/lib/Cake/
Included Files
    core
    app
        Config
        Controller
        Model
            0APP/Model/AppModel.php
        Other
            0APP/webroot/index.php
    plugins

where in local its showing

Included Files
Include Paths
    0C
    1\wamp\www\imobdevnew\lib;.;C
    2\php\pear
    3-> C:\wamp\www\imobdevnew\lib\Cake\
Included Files
    core
    app
        Other
            0APP/webroot\index.php
            1APP/Config\core.php
            2APP/Config\bootstrap.php
            3APP/Config\config.php
            4APP/Config\routes.php
            5APP/Controller\PortfoliosController.php
            6APP/Controller\AppController.php
            7APP/Model\portfolio.php
            8APP/Model\AppModel.php
            9APP/Config\database.php
            10APP/Model\category.php
    plugins

that means its not loading models.

Please help me...

2 Answers2

0

It seems to me that there is something wrong with your database, and not Linux. Is your database properly linked?

$this->Portfolio->recursive = 0;
$this->paginate = array(
    'fields' => array('Portfolio.id', 'Portfolio.application_name','Portfolio.category_id','Portfolio.description','Portfolio.screenshots','Portfolio.icon','Portfolio.bg_color_code','Portfolio.created','Category.id'),
    'limit' => 10,
    'order' => array(
        'Portfolio.id' => 'asc'
    )
);`
Femke
  • 79
  • 7
  • database configure properly and other all things working fine just getting problem with above query only –  Jun 14 '13 at 08:50
  • Does the field title in Category exists? Try the code in my comment, I've deleted the category.title part, because that triggers the error if I'm right – Femke Jun 14 '13 at 08:52
  • my table CREATE TABLE IF NOT EXISTS `categories` ( `id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(255) NOT NULL, `parent_id` int(11) NOT NULL DEFAULT '0', `status` enum('1','2') NOT NULL COMMENT '''1''=active,''2''=inactive', PRIMARY KEY (`id`) ) –  Jun 14 '13 at 09:13
  • I'm sorry, I was looking at the wrong part. If you look at the sql query in the error, you see that it tries to get all your fields from the portfolio table. So it looks like the hasmany/belongsto part is not working, while the code is good. What I do if that happens to me, is I manually add a join to my find or paginate. See this answer: http://stackoverflow.com/questions/5079908/cakephp-find-method-with-join and then the 'The (other) CakePHP way' part. I'm sorry that I don't have an other solution. – Femke Jun 14 '13 at 09:29
0

Linux is case-sensitive

Ominously showing up in the included-files on your windows install are these files:

7APP/Model\portfolio.php
...
10APP/Model\category.php

These files are the wrong case - so on linux they are not included, instead your models will be AppModel instances.

This will be the direct cause of the problem as without the model files being loaded, there will be no model associations either.

To fix the problem just ensure that all your files follow conventions - this means:

APP/Model/portfolio.php -> APP/Model/Portfolio.php
APP/Model/category.php -> APP/Model/Category.php

The filename, and other conventions, are sumarized in the documentation.

Community
  • 1
  • 1
AD7six
  • 63,116
  • 12
  • 91
  • 123
  • oh god thanks man,Before I got your answer i have tried it and its working,so silly mistake of me buddy. –  Jun 26 '13 at 09:45