To me it's pretty clear the schema dumper should dump the whole
schema, including information about primary keys. However, I don't
think the right way to get this info is through
ActiveRecord::Base.primary_key.
Agreed. My intention was to update the columns method on the connection adapter to set the primary attribute to true for the primary key. The one thing which we ran into while doing some work on this is that for tables with a primary key that is made up of more then one field we probably need to take the declaration of the primary key out of the table definition and put it as a seperate "add_primary_key" method that would then be recognized by ActiveRecord::Migration.
create_table :my_link_table, :id => false do |t|
t.column :table1_id, :integer
t.column :table2_id, :integer
end
add_primary_key :my_link_table, :table1_id, :table2_id
ActiveRecord::Base.primary_key uses declarations in the model classes
(set_primary_key, primary_key_prefix_type) to determine the primary
key. However, the schema dumper gets all of its information directly
from the database. To work correctly, I think the schema dumper
should get primary key info directly from the db as well, though this
would mean writing new code for most, if not all the adapters. One
added benefit if this was done, might be that primary key declarations
could be removed from the model code completely, making things simpler
for those using quirky primary keys.
The only downside that I can think of is that the query for retrieving columns with a primary key may be more costly then a query just for the column details. For the SQL Server Adapter getting the primary key requires including a LEFT OUTER JOIN on a sub-query.
- Steve
_______________________________________________ Rails-core mailing list [email protected] http://lists.rubyonrails.org/mailman/listinfo/rails-core
