This project is archived and is in readonly mode.
Add SQL methods to models
-
Pratik
- State changed from new to wontfix
It's not exactly 'Rails way' to use stored procedures. Having said that, Rails should make it simple to write such plugins nevertheless. So my suggestion is to release this feature as a plugin, and you could submit refactoring to Rails ( if needed ) to make such plugins less brittle and less hackish.
Thanks.
-
Jeremy Kemper
- State changed from wontfix to new
Agreed. Great patch, but this is a non-core feature.
-
Jeremy Kemper
- State changed from new to wontfix
-
Adam Sindelar
All right then, I'll make this into a plugin. However, in order to this to function properly, PostgreSQLAdapter needs to be aware of the possible schema in the name of a relation (table, function... anything...).
In Rails 2.0 ActiveRecord didn't attempt to quote table names (at least not in PostgreSQL), and everything sort of worked, but table-name-quoting introduced in ActiveRecord 2.1 broke that compatibility - so, would a patch that makes ActiveRecord aware of the schema part of a fully qualified name of a database relation be acceptable instead? It would involve changes to only several methods and would not affect any existing functionality.
Current behavior is that if we call...
set_table_table 'schema.table'
..we later get: SELECT [...] FROM "schema.table"
...which the database doesn't understand. Instead we should have: SELECT [...] FROM "schema"."table"
The obvious question is, why would someone want to use more than one schema per database in Rails. There are a number of reasons, but the most important are:
many database-clustering solutions work on per-schema basis; having separate schemata allows us to control which parts of the DB get synced, how often, and which are local only
some databases (like PostgreSQL) let the admin define different sets of permissions for each schema
sometimes, the database structure can get very large, and keeping tables logically sorted into several schemata helps not only navigating the structure, but also improves the ability to drop and load different parts of the database quickly
-
Jeremy Kemper
Yes, that's reasonable. The MySQL adapter already does.