Aryk Grosz wrote:
> ROR always converts :timestamp to :datetime. I've been googling and
> still havent found out why this is the case.
> 
> The mysql data type DATETIME takes up twice the amount of space as
> TIMESTAMP. What will break in my app if I change DATETIME to TIMESTAMP.
> Is this well documented somewhere?

I assume you're talking about migrations. So when you create a field 
such as

t.timestamp :my_field

the column in the database is actually a datetime. Each database adapter 
uses a hash to convert what is used in the migration to what is used in 
the database. This is done with a method called native_database_types. 
For example, the Postgres adapter defines:

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

This is actually my version to add support for bigints that I needed in 
a project. Notice that when :datetime or :timestamp is used, it becomes 
a timestamp in the database. If the MySQL adapter does not define this 
method explicitly, look at the abstract adapter. Also note the comment 
that I have in my overridden method. With great power comes great 
responsibility.

Peace.
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
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