This project is archived and is in readonly mode.
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
-
Robert Pankowecki August 27th, 2010 @ 07:27 PM
This is probably connected to this one: https://rails.lighthouseapp.com/projects/8994/tickets/5294-rails3-r...
-
Jeremy Kemper August 27th, 2010 @ 11:21 PM
- Milestone cleared.
- State changed from new to duplicate
- Assigned user set to Aaron Patterson
- Importance changed from to Low
-
mjs November 19th, 2010 @ 02:58 PM
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.
-
invadersmustdie November 26th, 2010 @ 09:26 AM
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
-
invadersmustdie November 26th, 2010 @ 09:48 AM
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 ...
-
swingman April 13th, 2011 @ 05:05 PM
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.
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>