Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is the documentation page for ActiveRecord data types?

I can't find the active record documenation page that has a list of all the data types.

Can someone help me out?

like image 476
Blankman Avatar asked Oct 18 '10 02:10

Blankman


People also ask

What is ActiveRecord in Ruby on Rails?

Active Record is the M in MVC - the model - which is the layer of the system responsible for representing business data and logic. Active Record facilitates the creation and use of business objects whose data requires persistent storage to a database.

What is ActiveRecord ORM?

Active Record: The Web's Favorite ORM “The active record pattern is an approach to accessing data in a database. A database table or view is wrapped into a class. Thus, an object instance is tied to a single row in the table. After creation of an object, a new row is added to the table upon save.

What is ActiveRecord relation?

The Relation Class. Having queries return an ActiveRecord::Relation object allows us to chain queries together and this Relation class is at the heart of the new query syntax. Let's take a look at this class by searching through the ActiveRecord source code for a file called relation.

Can you use ActiveRecord without rails?

One of the primary aspects of ActiveRecord is that there is very little to no configuration needed. It follow convention over configuration. ActiveRecord is commonly used with the Ruby-on-Rails framework but you can use it with Sinatra or without any web framework if desired.


2 Answers

If you're talking about the types for migrations, e.g. string, integer, datetime, etc, then you want ActiveRecord::ConnectionAdapters::TableDefinition, the column method. (Rails 5 edit: see also connection.add_column.)

As of this update, the standard types are:

  • :primary_key
  • :string
  • :text
  • :integer
  • :bigint
  • :float
  • :decimal
  • :numeric
  • :datetime
  • :time
  • :date
  • :binary
  • :boolean

The implementation of :decimal is different with each database, so I'd avoid it if possible. You may use a type not in this list as long as it is supported by your database (for example, :polygon in MySQL), but this will not be database agnostic and should also be avoided.

like image 58
Mark Thomas Avatar answered Sep 22 '22 02:09

Mark Thomas


You can also see ActiveRecord data types in sources. Each DBMS adapter contains its own mapping. For example, in MySQL case look at this file: https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb#L148 or get it by this line of code for current DBMS adapter:

ActiveRecord::Base.connection.native_database_types.keys 
like image 34
Psylone Avatar answered Sep 20 '22 02:09

Psylone