This project is archived and is in readonly mode.

#5478 ✓duplicate
Brian Durand

Postgres and Sqlite3 no longer able to map to database views

Reported by Brian Durand | August 27th, 2010 @ 04:55 PM | in 3.0.2

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.

Comments and changes to this ticket

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=""></a>