推进伪列排序
基本上我想创建一个伪列来进行排序。这是我的 SQL 查询,
SELECT I.*, ((I.width*175)/I.height) as relativeWidth
FROM Image I
order by relativeWidth asc
如何在 propel 中执行此操作而不直接编写 SQL?我不想创建视图并查询它。
Basically I want to make a pseudo column by which I'll sort. This is my SQL Query
SELECT I.*, ((I.width*175)/I.height) as relativeWidth
FROM Image I
order by relativeWidth asc
How can I do it in propel without writing direct SQL ? and I don't want to make a view and query it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否使用 Criteria(创建 where 子句的旧方法)?如果是这样,您可以简单地执行以下操作:
您还需要重写行类(I)中的 Hydro() 方法,以捕获额外的列(未经测试):
最后,您当然需要一个新值的 getter,但是这很容易。
如果您使用查询系统,可能有类似的方法可以做到这一点,尽管我不太熟悉它。
(编辑:添加返回值以确保正确性。)
Are you using Criteria (the old way of creating a where clause)? If so you can simply do:
You will also need to override the hydrate() method in your row class (I) in order to capture the extra column (untested):
Lastly of course you will need a getter for the new value, but that's easy.
If you are using the Query system there is probably a similar way to do it with that, though I am less familiar with it.
(Edit: added return value for correctness.)
这些要求在 Propel 1.5+ 版本中是可能的。 强烈建议您升级,因为它完全向后兼容,并包含许多新功能和修复。
您只需要了解新的 ActiveQuery api,而不是旧的良好标准。这样你就可以使用“虚拟列”来解决你的问题,只需看这里:
http://www.propelorm.org/reference/model-criteria.html#adding_columns
如果您在 symfony 中使用 Propel,只需从 https://github.com/propelorm/sfPropelORMPlugin 并按照 README 文件使其正常工作。
祝你好运!
Such requirements are possible in version 1.5+ of Propel. You are strongly encouraged to upgrade since it is fully backwards-compatible, with a lot of new features and fixes.
You just need to learn about the new ActiveQuery api instead of the ol' good Criteria. That way you can solve your problem using "virtual columns", just look here:
http://www.propelorm.org/reference/model-criteria.html#adding_columns
If you are using Propel inside symfony, just install the sfPropelORMPlugin from https://github.com/propelorm/sfPropelORMPlugin and follow the README file to get it working.
Good luck!