-
-
Save MTen/6893541 to your computer and use it in GitHub Desktop.
This file contains 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
[1] pry(main)> Book | |
=> Book(id: integer, title: string, author: string, abstract: text, created_at: datetime, updated_at: datetime) | |
[2] pry(main)> Book.create title: "Who Stole My Cheese?" | |
(0.1ms) begin transaction | |
SQL (5.1ms) INSERT INTO "books" ("created_at", "title", "updated_at") VALUES (?, ?, ?) [["created_at", Tue, 08 Oct 2013 23:14:31 UTC +00:00], ["title", "Who Stole My Cheese?"], ["updated_at", Tue, 08 Oct 2013 23:14:31 UTC +00:00]] | |
(14.9ms) commit transaction | |
=> #<Book id: 4, title: "Who Stole My Cheese?", author: nil, abstract: nil, created_at: "2013-10-08 23:14:31", updated_at: "2013-10-08 23:14:31"> | |
[3] pry(main)> Book.find(4) | |
Book Load (0.3ms) SELECT "books".* FROM "books" WHERE "books"."id" = ? LIMIT 1 [["id", 4]] | |
=> #<Book id: 4, title: "Who Stole My Cheese?", author: nil, abstract: nil, created_at: "2013-10-08 23:14:31", updated_at: "2013-10-08 23:14:31"> | |
[4] pry(main)> book = Book.find(4) | |
Book Load (0.2ms) SELECT "books".* FROM "books" WHERE "books"."id" = ? LIMIT 1 [["id", 4]] | |
=> #<Book id: 4, title: "Who Stole My Cheese?", author: nil, abstract: nil, created_at: "2013-10-08 23:14:31", updated_at: "2013-10-08 23:14:31"> | |
[5] pry(main)> book.title | |
=> "Who Stole My Cheese?" | |
[6] pry(main)> book.created_at | |
=> Tue, 08 Oct 2013 23:14:31 UTC +00:00 | |
[7] pry(main)> book.updated_at | |
=> Tue, 08 Oct 2013 23:14:31 UTC +00:00 | |
[8] pry(main)> x = Book.find(234) | |
Book Load (0.1ms) SELECT "books".* FROM "books" WHERE "books"."id" = ? LIMIT 1 [["id", 234]] | |
ActiveRecord::RecordNotFound: Couldn't find Book with id=234 | |
from /home/joe/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/relation/finder_methods.rb:198:in `raise_record_not_found_exception!' | |
[9] pry(main)> Book.find_by_title("Who Stole My Cheese?") | |
Book Load (0.4ms) SELECT "books".* FROM "books" WHERE "books"."title" = 'Who Stole My Cheese?' LIMIT 1 | |
=> #<Book id: 4, title: "Who Stole My Cheese?", author: nil, abstract: nil, created_at: "2013-10-08 23:14:31", updated_at: "2013-10-08 23:14:31"> | |
[10] pry(main)> Book.find_by_title("GOOSGBT") | |
Book Load (0.2ms) SELECT "books".* FROM "books" WHERE "books"."title" = 'GOOSGBT' LIMIT 1 | |
=> nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment