On Nov 5, 2:40 pm, Phillip Koebbe <[EMAIL PROTECTED]>
wrote:
> Each database adapter has the ability to define the database types Rails
> uses when building DDL. The method used is native_database_types, which
> is, in the case of PostgreSQL, found in the PostgreSQL class of the
> ConnectionAdapters module of the ActiveRecord module. Override it and
> supply what you want. Here is what I use to add bigint support to AR:
>
> class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
>   # in order to add or change the datatypes, this function
>   # must be overriden.  Be careful, then, to not remove anything.
>   # That carries with it the warning that if Rails Core changes
>   # this function, this override will do away with those changes!
>   def native_database_types
>     {
>       :primary_key => "serial primary key",
>       :string      => { :name => "character varying", :limit => 255 },
>       :text        => { :name => "text" },
>       :integer     => { :name => "integer" },
>       :float       => { :name => "float" },
>       :decimal     => { :name => "decimal" },
>       :datetime    => { :name => "timestamp" },
>       :timestamp   => { :name => "timestamp" },
>       :time        => { :name => "time" },
>       :date        => { :name => "date" },
>       :binary      => { :name => "bytea" },
>       :boolean     => { :name => "boolean" },
>       :bigint      => { :name => "int8" }
>     }
>   end
> end
>
> Put that in a file that gets loaded when the Rails environment gets
> loaded, and you've overridden the method. In your case, if you want to
> add char support, you might do something like:
>
>   def native_database_types
>     {
>       :primary_key => "serial primary key",
>       :char => { :name => "character", :limit => 255 },
>       :string      => { :name => "character varying", :limit => 255 },
>       :text        => { :name => "text" },
>       ...
>     }
>   end
>
> and then in your migration
>
> t.column :char, :my_column, :limit => 5

Whoa! Awesome! I would like to apply that and the foreign key thing,
but is there a folder where I can save and call my file? Where do you
place it in your case?

I was gonna ask you about how to implement the serial datatype, but
all the explanation you gave me for overriding answered that question.

Later...

The Neurochild.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to