This project is archived and is in readonly mode.

#316 ✓wontfix
Martin Bosner

select with alias tablenames broken

Reported by Martin Bosner | June 3rd, 2008 @ 02:57 PM

This worked before i upgraded to rails 2.1 (from 1.2.6) using mysql:

Model.find(:all,:conditions=>"1",:joins=>"as alias left join model2 as alias2 on alias.id = alias2.line_id")

To get it working you need to remove the alias or insert a custom select option:

Model.find(:all,select=>"*",:conditions=>"1",:joins=>"as alias left join model2 as alias2 on alias.id = alias2.line_id")

It seems that the later rails version add the default model tablename to the query e.g.:

select original_table_name.* from ...

That does not work because it needs the alias in the statement.

Is that a bug or a feature?

Comments and changes to this ticket

  • Tarmo Tänav

    Tarmo Tänav August 23rd, 2008 @ 02:02 PM

    • State changed from “new” to “wontfix”
    • Tag cleared.

    I believe this is a feature, we wouldn't want joins to mask any attribute without explicit user approval. For example if you join multiple tables and select "*" then it becomes unclear which table's "id" attribute should be returned.

    I'll close this for now, until convincing arguments are given for why this should be changed.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages