Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in Models Meta-Data Component? Wrong table requested if source-variable of model changed. #2415

Closed
swen100 opened this issue May 9, 2014 · 3 comments

Comments

@swen100
Copy link

swen100 commented May 9, 2014

Hi,

I use latest Phalcon 1.3.2 on OpenSuse.
I have a (one) model-class in which I set the source and database dynamically.
The class has the following definition:

class FeatureCode extends \Phalcon\Mvc\Model {
    public static $database = 'xxxxx';
    public static $source = 'fccode_area';

    public function initialize() {
        $this->setConnectionService('db');
        $this->setSchema(static::$database);
        $this->setSource(static::$source);
    }
    public function getSource() {
        return static::$source;
    }
    public function getSchema() {
        return static::$database;
    }
}

in this example i have two tables: fccode_area and fccode_symbol.

This is what i found out:

// i set the table to fccode_symbol: 
FeatureCode::$source = 'fccode_symbol';
// i try to find an object which is definitly not in this table. 
FeatureCode::findFirst("FC = '31167101'");
//Query is o.k, all works fine.
// i set the table to fccode_area: 
FeatureCode::$source = 'fccode_area';
// i try to find the object with same query and which is definitly there. 
// At this point the query becomes false.
FeatureCode::findFirst("FC = '31167101'");

Take a look at the query-log:

***symbol-table is queried, all o.k.***
[16:52:21] SELECT IF(COUNT(*)>0, 1 , 0) FROM `INFORMATION_SCHEMA`.`TABLES` WHERE 
`TABLE_NAME`= 'fccode_symbol' AND `TABLE_SCHEMA`='atkis_fc_050_vv'

[16:52:21] DESCRIBE `atkis_fc_050_vv`.`fccode_symbol`

[16:52:21] SELECT `fccode_symbol`.`FC`, `fccode_symbol`.`Symbol`, `fccode_symbol`.`Basescale`,
 `fccode_symbol`.`Height`, `fccode_symbol`.`Width`, `fccode_symbol`.`Scalable`,... FROM 
`atkis_fc_050_vv`.`fccode_symbol` WHERE `fccode_symbol`.`FC` = '31167101' LIMIT :1 [1]

***area-table is queried, all o.k.***
SELECT IF(COUNT(*)>0, 1 , 0) FROM `INFORMATION_SCHEMA`.`TABLES` WHERE 
`TABLE_NAME`= 'fccode_area' AND `TABLE_SCHEMA`='atkis_fc_050_vv'

[16:52:21] DESCRIBE `atkis_fc_050_vv`.`fccode_area`

***correct columns, but the table-name is wrong!!!***
[16:52:21] SELECT `fccode_symbol`.`FC`, `fccode_symbol`.`BorderColor`, 
`fccode_symbol`.`BorderColorCmyk`, `fccode_symbol`.`BorderStyle`, 
`fccode_symbol`.`BorderWidth`, `fccode_symbol`.`FillColor`, ... FROM 
`atkis_fc_050_vv`.`fccode_symbol` WHERE `fccode_symbol`.`FC` = '31167101' LIMIT :1 [1]

 [WARNING, SQLSTATE[42S22]: Column not found: 1054 Unknown column 
'fccode_symbol.BorderColor' in 'field list', 1399647141, 2014-05-09 16:05:21]

Phalcon takes the columns from the area-table but queries symbol-table...

It is strange, that in the "DESCRIBE"-query the table-name is correct, but finally the wrong will be used...

Swen

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@dreamsxin
Copy link
Contributor

Your usage has been damage to the Models Meta-Data, you can overrider method Model::getModelsMetaData.

@swen100
Copy link
Author

swen100 commented May 12, 2014

so, is this a bug in the Models Meta-Data component?

i dont want to override the method. But if so, what would be the advantage?

The requested columns are correct, but only the table-name is wrong.
It is strange, that in the "DESCRIBE"-query the table-name is correct, but finally the wrong will be used...

@swen100 swen100 changed the title wrong columns requested if source of model changed Bug in Models Meta-Data Component? Wrong columns requested if source of model changed. May 12, 2014
@dreamsxin
Copy link
Contributor

I'm sorry, before didn't watch carefully, I again under test.

@swen100 swen100 changed the title Bug in Models Meta-Data Component? Wrong columns requested if source of model changed. Bug in Models Meta-Data Component? Wrong table requested if source of model changed. May 12, 2014
@swen100 swen100 changed the title Bug in Models Meta-Data Component? Wrong table requested if source of model changed. Bug in Models Meta-Data Component? Wrong table requested if source-variable of model changed. May 12, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants