【发布时间】:2013-10-22 17:30:40
【问题描述】:
我有以下两张表:
table_a:
id_table_a: { type: integer, primaryKey: true, autoIncrement: true, required: true }
name: { type: varchar(255) }
id_table_b: { type: integer, foreignTable: table_b, foreignReference: id_table_b }
table_b:
id_table_b: { type: integer, primaryKey: true, autoIncrement: true, required: true }
value_1: { type: varchar(255) }
value_2: { type: integer }
我想使用 select 方法构建 SQL 查询以跳过水合,同时在连接表上使用别名:
TableAQuery::create()
->useTableBQuery('a')
// some filters methods
->endUse()
->useTableBQuery('b')
// some filters methods
->endUse()
->select(array('a.value_1', 'b.value_2'))
->find();
现在问题来了。不断地将a 和b 别名更改为table_b,从而生成错误的SQL,如下所示:
SELECT table_b.value_1 AS "a.value_1", table_b.value_2 AS "b.value_2" FROM `table_a`
LEFT JOIN `table_b` `a` ON (table_a.id_table_b=a.id_table_b)
LEFT JOIN `table_b` `b` ON (table_a.id_table_b=b.id_table_b)
而不是
SELECT a.value_1 AS value_1, b.value_2 AS value_2 FROM `table_a`
LEFT JOIN `table_b` `a` ON (table_a.id_table_b=a.id_table_b)
LEFT JOIN `table_b` `b` ON (table_a.id_table_b=b.id_table_b)
我该如何处理?我使用 Propel 1.6.9
更新
我也查了propel 1.7.1,没区别。
【问题讨论】:
-
有趣的问题,我也不知道答案;也许这是一个 Propel 错误。你还需要答案吗?如果你这样做,我会在它上面加一个赏金。如果是这样,请在 @halfer 上联系我。
-
@halfer 如果您能帮助引起对该主题的关注,那就太好了。我几乎每天都在使用 Propel,这不是我第一次因为这个问题而陷入困境。
-
我想我有同样的问题? stackoverflow.com/questions/20127660/…不知道有没有提交过bug?
-
@KarasQ,让我知道你如何接受 jchamberlain 的建议。
-
@halfer jchamberlain 的建议与我的示例产生的结果相同。