aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source/active_record_postgresql.md
diff options
context:
space:
mode:
Diffstat (limited to 'guides/source/active_record_postgresql.md')
-rw-r--r--guides/source/active_record_postgresql.md14
1 files changed, 9 insertions, 5 deletions
diff --git a/guides/source/active_record_postgresql.md b/guides/source/active_record_postgresql.md
index dfa488773e..a5649e3903 100644
--- a/guides/source/active_record_postgresql.md
+++ b/guides/source/active_record_postgresql.md
@@ -8,6 +8,7 @@ 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 back your Active Record models with database views.
--------------------------------------------------------------------------------
@@ -51,11 +52,13 @@ Document.create payload: data
```ruby
# db/migrate/20140207133952_create_books.rb
-create_table :book do |t|
+create_table :books do |t|
t.string 'title'
t.string 'tags', array: true
t.integer 'ratings', array: true
end
+add_index :books, :tags, using: 'gin'
+add_index :books, :ratings, using: 'gin'
# app/models/book.rb
class Book < ActiveRecord::Base
@@ -322,7 +325,8 @@ macbook.address
* [type definition](http://www.postgresql.org/docs/9.3/static/datatype-geometric.html)
-All geometric types are mapped to normal text.
+All geometric types, with the exception of `points` are mapped to normal text.
+A point is casted to an array containing `x` and `y` coordinates.
UUID Primary Keys
@@ -370,8 +374,8 @@ Document.where("to_tsvector('english', title || ' ' || body) @@ to_tsquery(?)",
"cat & dog")
```
-Views
------
+Database Views
+--------------
* [view creation](http://www.postgresql.org/docs/9.3/static/sql-createview.html)
@@ -426,7 +430,7 @@ second = Article.create! title: "Brace yourself",
Article.count # => 1
first.archive!
-p Article.count # => 2
+Article.count # => 2
```
NOTE: This application only cares about non-archived `Articles`. A view also