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

Many association ordering doesn't work after conversion to sql-query #70

Closed
czkody opened this issue Mar 10, 2013 · 3 comments
Closed

Comments

@czkody
Copy link

czkody commented Mar 10, 2013

Hi,

Thank you very much for your work on this interresting project. It helps me a lot.

It seems there is a problem with ordering of query through many association after the conversion to sql-query using.

Regarding to #68 model definition following code produced error.

var Category = require('../models/Category');

exports.subcategories = function(req, res, next) {
    Category(Number(req.params['category'])).getSuccessors({distance: 1},['name', 'A'], function(err, categories) {
        res.json(categories);
    });
}

Produced SQL Code

SELECT
  *
FROM 
  `category` AS `t1` 
  JOIN `category_tree` AS `t2` ON `t2`.`successor_id` = `t1`.`id` 
WHERE 
  (`t2`.`predecessor_id` = 7 AND `distance` = 1) 
ORDER BY 
  `category.name` ASC

There is a table name used instead of table alias in order by clause.

With regards,
Kody

@dresende
Copy link
Owner

Thank you for pointing this out. I was afraid of this situations, that's why I haven't released a npm version with sql-query yet. I'm going to fix this now.

@dresende
Copy link
Owner

Please try it now, I made a change to sql-query and orm that should correctly use the table alias and also correctly escape the table+column.

@czkody
Copy link
Author

czkody commented Mar 10, 2013

Yes, it works fine, thank you very much :) Nice work !!!

@czkody czkody closed this as completed Mar 10, 2013
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

2 participants