Although there is the undocumented native_database_types method that returns a hash in each ActiveRecord adapter included in Rails.
It is not undocumented, it is private API and should not be used in applications. If you use the add_reference/add_belongs_to methods in a migration, they use the integer type rather than the primary_key type for foreign_keys, which is correct since the primary key type can define autoincrement, however you want the foreign key column type itself (e.g. integer, etc.) to match the primary key’s type, so it seems like there should be another foreign_key type defined in each adapter. This way you could actually get the foreign_key type from the adapter in the add_reference/add_belongs_to methods and wouldn’t need to instead use add_column as a workaround. Instead of adding a new type why not make add_reference/add_belongs_to accept the column type? This will provide a way of declaring the foreign key column with the right type without having to add a type that is not native. Rafael Mendonça França http://twitter.com/rafaelfranca https://github.com/rafaelfranca On Wed, Sep 3, 2014 at 6:49 PM, Gary Weaver <garyswea...@gmail.com> wrote: Although there is the undocumented `native_database_types` method that > returns a hash in each ActiveRecord adapter included in Rails, e.g.: > > def native_database_types #:nodoc: > NATIVE_DATABASE_TYPES > end > > If you use the add_reference/add_belongs_to methods in a migration, they > use the integer type rather than the primary_key type for foreign_keys, > which is correct since the primary key type can define autoincrement, > however you want the foreign key column type itself (e.g. integer, etc.) to > match the primary key's type, so it seems like there should be another > foreign_key type defined in each adapter. This way you could actually get > the foreign_key type from the adapter in the add_reference/add_belongs_to > methods and wouldn't need to instead use add_column as a workaround. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to rubyonrails-core+unsubscr...@googlegroups.com. > To post to this group, send email to rubyonrails-core@googlegroups.com. > Visit this group at http://groups.google.com/group/rubyonrails-core. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/d/optout.