Skip to content

Instantly share code, notes, and snippets.

@solars
Created August 30, 2011 08:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save solars/9fa01f6d150c3be6bd04 to your computer and use it in GitHub Desktop.
Save solars/9fa01f6d150c3be6bd04 to your computer and use it in GitHub Desktop.
# in the controller, very simple model for example, having string ip and string description fields:
DocType.create(:name => request.remote_ip, :description => 'request') # remote_ip is 127.0.0.1
DocType.create(:name => "127.0.0.1", :description => 'string')
# in rails console, only the string assigned object is returned:
ruby-1.9.2-p180 :004 > DocType.find_all_by_name('127.0.0.1')
DocType Load (0.7ms) SELECT "doc_types".* FROM "doc_types" WHERE "doc_types"."name" = '127.0.0.1'
=> [#<DocType id: 7, name: "127.0.0.1", description: "string">]
# sqlite shows 2 records as:
sqlite> select * from doc_types;
6|127.0.0.1|request
7|127.0.0.1|string
# dump shows:
sqlite> .dump doc_types
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE "doc_types" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "description" varchar(255));
INSERT INTO "doc_types" VALUES(6,X'3132372E302E302E31','request');
INSERT INTO "doc_types" VALUES(7,'127.0.0.1','string');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment