Last active
December 17, 2015 04:48
-
-
Save linjunpop/5552973 to your computer and use it in GitHub Desktop.
https://github.com/dockyard/postgres_ext Integer Array save with String value.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| rails (3.2.13) | |
| pg (0.14.1) | |
| pg_array_parser (0.0.8) | |
| postgres_ext (0.3.1) | |
| activerecord (~> 3.2.0) | |
| pg_array_parser (~> 0.0.8) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class AddSeenByToDocuments < ActiveRecord::Migration | |
| def change | |
| add_column :documents, :seen_by, :integer, array: true, default: [] | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [19] pry(main)> d.seen_by = [4, "f"] | |
| => [4, "f"] | |
| [20] pry(main)> d.save | |
| ... | |
| (1.2ms) UPDATE "documents" SET "seen_by" = '{4,0}' ... | |
| ... | |
| => true | |
| [21] pry(main)> d.reload.seen_by | |
| Document Load (0.6ms) SELECT "documents".* FROM "documents" WHERE "documents"."id" = $1 LIMIT 1 [["id", 108]] | |
| => [4, 0] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment