我试图弄清楚为什么角色_用户表的 created_at 列在为用户分配角色时似乎占用了用户一个。它不应该有自己的创建日期吗?有什么帮助吗?
ruby-1.8.7-p174 > Time.now
=> 2 月 24 日星期四 15:50:11 +0100 2011
ruby-1.8.7-p174 > User.last.has_role!"installer"
用户负载 (0.5ms) SELECT * FROM "users" ORDER BY users.id DESC LIMIT 1
Country Load (0.2ms) SELECT * FROM "countries" WHERE ("countries"."id" = 106)
角色负载 ( 0.2ms) SELECT * FROM "roles" WHERE (name = 'installer' and authorizable_type IS NULL and authorizable_id IS NULL) LIMIT 1
Role Load (0.1ms) SELECT "roles".id FROM "roles" INNER JOIN "roles_users" ON "角色".id = "roles_users".role_id WHERE ("roles"."id" = 2) AND ("roles_users".user_id = 31 ) LIMIT 1
SQL (0.', ' 2010-09-16 14:11:24 ', 2, 31)
角色加载 (0.5ms) SELECT * FROM "roles" INNER JOIN "roles_users" ON "roles".id = "roles_users".role_id WHERE ( "roles_users".user_id = 31 )
=> [#Role id: 2, name: "installer", authorizable_type: nil, authorizable_id: nil, created_at: "2010-09-16 14:11:24", updated_at: "2010 -09-16 14:11:24">]
ruby-1.8.7-p174 > Role.find_by_name("installer")
角色加载 (0.3ms) SELECT * FROM "roles" WHERE ("roles"."name" = 'installer') LIMIT 1
=> #Role id: 2, name: "installer", authorizable_type: nil, authorizable_id: nil, created_at: " 2010-09-16 14:11:24 ",更新时间:"2010-09-16 14:11:24">