Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >> a_user = User.new :email => "badboyz2@gmai.com"
- => #<User id: nil, email: "badboyz2@gmai.com", password: nil, name: nil, created_at: nil, updated_at: nil>
- >> a_user.role = Role.teacher
- Role Load (0.2ms) SELECT "roles".* FROM "roles" WHERE "roles"."name" = 'teacher' LIMIT 1
- => #<Role id: 1, name: "teacher", created_at: "2011-07-07 07:05:37", updated_at: "2011-07-07 07:46:30">
- >> a_user.save!
- AREL (46.6ms) INSERT INTO "users" ("email", "password", "name", "created_at", "updated_at") VALUES ('badboyz2@gmai.com', NULL, NULL, '2011-07-07 08:04:26.281168', '2011-07-07 08:04:26.281168')
- => true
- >> a_user.reload
- User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = 16 LIMIT 1
- => #<User id: 16, email: "badboyz2@gmai.com", password: nil, name: nil, created_at: "2011-07-07 08:04:26", updated_at: "2011-07-07 08:04:26">
- >> a_user.role
- Role Load (0.2ms) SELECT "roles".* FROM "roles" WHERE "roles"."id" = 1 LIMIT 1
- => #<Role id: 1, name: "teacher", created_at: "2011-07-07 07:05:37", updated_at: "2011-07-07 07:46:30">
- >> user = User.where(:email => "badboyz2@gmai.com").includes(:role)
- User Load (0.9ms) SELECT "users"."id" AS t0_r0, "users"."email" AS t0_r1, "users"."password" AS t0_r2, "users"."name" AS t0_r3, "users"."created_at" AS t0_r4, "users"."updated_at" AS t0_r5, "roles"."id" AS t1_r0, "roles"."name" AS t1_r1, "roles"."created_at" AS t1_r2, "roles"."updated_at" AS t1_r3 FROM "users" LEFT OUTER JOIN "roles" ON "roles"."id" IS NULL WHERE "users"."email" = 'badboyz2@gmai.com'
- => [#<User id: 16, email: "badboyz2@gmai.com", password: nil, name: nil, created_at: "2011-07-07 08:04:26", updated_at: "2011-07-07 08:04:26">]
- >> user.first.role
- => nil
Add Comment
Please, Sign In to add comment