aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/test/cases/adapters/postgresql/uuid_test.rb6
-rw-r--r--guides/source/active_record_postgresql.md32
2 files changed, 33 insertions, 5 deletions
diff --git a/activerecord/test/cases/adapters/postgresql/uuid_test.rb b/activerecord/test/cases/adapters/postgresql/uuid_test.rb
index bdf8e15e3e..ffce7c0d5f 100644
--- a/activerecord/test/cases/adapters/postgresql/uuid_test.rb
+++ b/activerecord/test/cases/adapters/postgresql/uuid_test.rb
@@ -45,12 +45,14 @@ class PostgresqlUUIDTest < ActiveRecord::TestCase
UUIDType.reset_column_information
column = UUIDType.columns.find { |c| c.name == 'thingy' }
assert_equal "uuid_generate_v1()", column.default_function
-
+
@connection.change_column :uuid_data_type, :thingy, :uuid, null: false, default: "uuid_generate_v4()"
-
+
UUIDType.reset_column_information
column = UUIDType.columns.find { |c| c.name == 'thingy' }
assert_equal "uuid_generate_v4()", column.default_function
+ ensure
+ UUIDType.reset_column_information
end
def test_data_type_of_uuid_types
diff --git a/guides/source/active_record_postgresql.md b/guides/source/active_record_postgresql.md
index ae767769dd..fddfe24abb 100644
--- a/guides/source/active_record_postgresql.md
+++ b/guides/source/active_record_postgresql.md
@@ -12,10 +12,9 @@ It describes how to properly setup Active Record for PostgreSQL.
After reading this guide, you will know:
-
* How to use PostgreSQL's datatypes.
-* How to use UUID Primary keys.
-* How to implement Full text search with PostgreSQL.
+* How to use UUID primary keys.
+* How to implement full text search with PostgreSQL.
--------------------------------------------------------------------------------
@@ -291,6 +290,33 @@ user.save!
The types `inet` and `cidr` are mapped to Ruby [`IPAddr`](http://www.ruby-doc.org/stdlib-2.1.1/libdoc/ipaddr/rdoc/IPAddr.html) objects. The
`macaddr` type is mapped to normal text.
+```ruby
+# db/migrate/20140508144913_create_devices.rb
+create_table(:devices, force: true) do |t|
+ t.inet 'ip'
+ t.cidr 'network'
+ t.macaddr 'address'
+end
+
+# app/models/device.rb
+class Device < ActiveRecord::Base
+end
+
+# Usage
+macbook = Device.create(ip: "192.168.1.12",
+ network: "192.168.2.0/24",
+ address: "32:01:16:6d:05:ef")
+
+macbook.ip
+# => #<IPAddr: IPv4:192.168.1.12/255.255.255.255>
+
+macbook.network
+# => #<IPAddr: IPv4:192.168.2.0/255.255.255.0>
+
+macbook.address
+# => "32:01:16:6d:05:ef"
+```
+
### Geometric Types
* [type definition](http://www.postgresql.org/docs/9.3/static/datatype-geometric.html)