选择列表中不明确的列命名 -- DataMapper for Ruby

发布于 2024-09-12 17:01:05 字数 510 浏览 2 评论 0原文

在 DataMapper 中,我有这样的表:

Foo
===
id            Integer
other_columns Whatever

Fuzz
===
id            Integer
other_columns Whatever

对于关联:

class Fuzz
  has 1, :foo, :child_key => :id
end

当我调用时: Fuzz.first.foo

DataMapper 生成如下 SQL: select raw_sql_.* from(SELECT "ID", "OTHER_COLUMNS", "ID" FROM "FOO" WHERE ... ORDER BY "ID")

由于存在“ORDER BY”子句,Oracle 返回说: 选择列表中的列命名不明确

如何避免这种情况?这是一个遗留数据库系统,因此我无法更改架构。

In DataMapper, I have tables like this:

Foo
===
id            Integer
other_columns Whatever

Fuzz
===
id            Integer
other_columns Whatever

For associations:

class Fuzz
  has 1, :foo, :child_key => :id
end

When I call:
Fuzz.first.foo

DataMapper generates SQL like this:
select raw_sql_.* from(SELECT "ID", "OTHER_COLUMNS", "ID" FROM "FOO" WHERE ... ORDER BY "ID")

Because of the "ORDER BY" clause, Oracle comes back saying:
ambiguous column naming in select list

How do I avoid this situation? This is a legacy database system, so I have no option to change the schema.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

给不了的爱 2024-09-19 17:01:05

从您的帖子中,不清楚为什么您将 ID 添加到内部选择两次。是不是因为你从两个表中选择了ID?然后,在选择列表中,在它们前面加上表名称,并为它们提供您选择的别名,例如

SELECT FOO."ID" AS FOO_ID, "OTHER_COLUMNS", FUZZ."ID" AS FUZZ_ID
FROM FOO, FUZZ
WHERE ...
ORDER BY FOO.ID

From your post, it is not clear why you add ID twice to the inner select. Is it because you select IDs from two tables? Then, in the select list, precede them with table names and give aliases of your choice to them like

SELECT FOO."ID" AS FOO_ID, "OTHER_COLUMNS", FUZZ."ID" AS FUZZ_ID
FROM FOO, FUZZ
WHERE ...
ORDER BY FOO.ID
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文