Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Postgres and Sqlite3 no longer able to map to database views

#5478

In Rails 2 ActiveRecord allowed you to map a class to a database view instead of to a table. In Rails 3, ActiveRecord can still load models from a view (MyModel.first and MyModel.all work), however, arel won't allow you to query on one because the ConnectionAdapter.table_exists? method returns false in the PostgreSQL and SQLite3 implementations.

This patch restores the ability to query on views by updating the code for table_exists? for the PostgreSQL and SQLite3 adapters to return views as well as tables (the MySQL adapter has always returned both).

I've looked into the code quite a bit and there are still problems using views (for example, the schema dumper will output them as tables). This patch at least restores a feature that can be very useful when using Rails on top of a legacy database.

Reported by Brian Durand · August 27th, 2010 @ 04:55 PM

State: duplicate
Milestone: 3.0.2
Assigned to: Aaron Patterson Aaron Patterson
Importance: Low

Activity

  1. Robert Pankowecki
  2. Jeremy Kemper
    Jeremy Kemper
    • Milestone cleared.
    • State changed from new to duplicate
    • Assigned user set to Aaron Patterson
    • Importance changed from to Low

    August 27th, 2010 @ 11:21 PM

  3. Jeremy Kemper
  4. mjs
    mjs

    What is the status of this bug? It is still present in 3.0.3. The supplied patch corrects the issue for Postgres. (I have not tested Sqlite3).

    Also, I don't think that this is a duplicate as indicated in the first comment.

    November 19th, 2010 @ 02:58 PM

  5. invadersmustdie
    invadersmustdie

    I can confirm that the issue still occurs in Rails 3.0.3

    == bundle show activemodel (3.0.3) activerecord (3.0.3) activesupport (3.0.3) rails (3.0.3) ....

    The patch proposed by Brian Durand fixes this behavior

    November 26th, 2010 @ 09:26 AM

  6. invadersmustdie
    invadersmustdie

    I can confirm that the issue still occurs in Rails 3.0.3

    The patch proposed by Brian Durand fixes this behavior

    bundle show

    • activemodel (3.0.3)
    • activerecord (3.0.3)
    • activesupport (3.0.3)
    • rails (3.0.3)
    • ...

    must have missed the formatting help ...

    November 26th, 2010 @ 09:48 AM

  7. bingbing
  8. swingman
    swingman

    I have just been badly bitten by this issue when upgrading to Rails 3.0.5.
    Brian Durand's patch seems to do the trick.

    April 13th, 2011 @ 05:05 PM