views:

22

answers:

1

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.

A: 

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
Frank
No, DataMapper generates the SQL, not me. Sorry for being unclear.
Josiah Kiehl