-
-
Save nhmood/2358b5ceb9e275cdfb3b 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
get '/test' do | |
@user = User.get(1) # User already created | |
pp @user | |
@test = Test.create(:user => @user) | |
pp @test | |
pp @test.save | |
pp @test.errors | |
end |
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
class Test | |
include DataMapper::Resource | |
property :id, Serial | |
belongs_to :user | |
end |
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
class User | |
include DataMapper::Resource | |
property :id, Serial, :key => true | |
property :username, String, | |
:required => true, | |
:unique => true, | |
:length => 6..25 | |
property :password, BCryptHash, :required => true | |
attr_accessor :password_confirm | |
validates_presence_of :password_confirm | |
validates_length_of :password_confirm, :min => 6 | |
validates_confirmation_of :password, :confirm => :password_confirm | |
property :email, String, | |
:required => true, | |
:unique => true, | |
:format => :email_address | |
property :created, DateTime | |
property :accessed, DateTime | |
property :avatar, Text | |
has n, :tests | |
end |
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
~ (0.000520) PRAGMA table_info("users") | |
~ (0.000381) PRAGMA table_info("users") | |
~ (0.000042) PRAGMA table_info("users") | |
~ (0.000031) PRAGMA table_info("users") | |
~ (0.000028) PRAGMA table_info("users") | |
~ (0.000021) PRAGMA table_info("users") | |
~ (0.000021) PRAGMA table_info("users") | |
~ (0.000022) PRAGMA table_info("users") | |
~ (0.000032) PRAGMA table_info("tests") | |
~ (0.000028) PRAGMA table_info("tests") | |
~ (0.000018) PRAGMA table_info("tests") | |
~ (0.000031) PRAGMA table_info("tokens") | |
~ (0.000020) PRAGMA table_info("tokens") | |
~ (0.000025) PRAGMA table_info("tokens") | |
~ (0.000019) PRAGMA table_info("tokens") | |
~ (0.000020) PRAGMA table_info("tokens") | |
~ (0.000106) SELECT "id", "username", "password", "email", "created", "accessed" FROM "users" WHERE "id" = 1 LIMIT 1 | |
#<User @id=1 @username="nhmood" @password="$2a$10$E8B0aB0MWh87jRqiOFQlf.lFKBcvQJWXol6dP8BXdVvKasTzs0oxS" @email="my@email.com" @created=#<DateTime: 2014-04-22T22:46:07-04:00 ((2456771j,9967s,0n),-14400s,2299161j)> @accessed=#<DateTime: 2014-04-22T22:46:07-04:00 ((2456771j,9967s,0n),-14400s,2299161j)> @avatar=<not loaded>> | |
~ (0.000087) SELECT "id", "avatar" FROM "users" WHERE "id" = 1 ORDER BY "id" | |
~ (0.000064) SELECT "id" FROM "users" WHERE "username" = 'nhmood' ORDER BY "id" LIMIT 1 | |
~ (0.000072) SELECT "id" FROM "users" WHERE "email" = 'my@email.com' ORDER BY "id" LIMIT 1 | |
#<Test @id=nil @user_id=1> | |
~ (0.000067) SELECT "id" FROM "users" WHERE "username" = 'nhmood' ORDER BY "id" LIMIT 1 | |
~ (0.000053) SELECT "id" FROM "users" WHERE "email" = 'my@email.com' ORDER BY "id" LIMIT 1 | |
false | |
#<DataMapper::Validations::ValidationErrors:0xb90f1888 @resource=#<Test @id=nil @user_id=1>, @errors={}> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment