Acl9关联表created_at列问题
我试图弄清楚为什么在为用户分配角色时,roles_users 表的created_at 列似乎采用用户1。它不应该有自己的创建日期吗?有什么帮助吗?
ruby-1.8.7-p174>现在时间
=> 2 月 24 日星期四 15:50:11 +0100 2011
红宝石-1.8.7-p174 > User.last.has_role! “安装程序”
用户负载 (0.5ms) SELECT * FROM "users" ORDER BY users.id DESC LIMIT 1
国家负载 (0.2ms) SELECT * FROM "countries" WHERE ("countries"."id" = 106)
角色加载 (0.2ms) SELECT * FROM "roles" WHERE (name = 'installer' andauthorized_type IS NULL andauthorized_id IS NULL) LIMIT 1
角色加载(0.1ms)从“roles”INNER JOIN“roles_users”中选择“roles”.id ON“roles”.id =“roles_users”.role_id WHERE(“roles”.“id”= 2)AND(“roles_users” .user_id = 31 ) 限制 1
SQL (0.3ms) INSERT INTO "roles_users" ("created_at", "updated_at", "role_id", "user_id") VALUES ('2010-09-16 14:11:24', ' 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 )
=> [#角色 id:2,名称:“安装程序”,authorized_type:nil,authorized_id:nil,created_at:“2010-09-16 14:11:24”,updated_at:“2010-09-16 14:11:24” >]
红宝石-1.8.7-p174 > Role.find_by_name("安装程序")
角色加载 (0.3ms) SELECT * FROM "roles" WHERE ("roles"."name" = 'installer') LIMIT 1
=> #Role id: 2, name: "installer",authorized_type: nil,authorized_id:nil,created_at:"2010-09-16 14:11:24",updated_at:"2010-09-16 14:11:24">
I'm trying to figure out why the created_at column of roles_users' table seems to take the user one when assigning a role to a user. It should not have its own creation date? Any helps?
ruby-1.8.7-p174 > Time.now
=> Thu Feb 24 15:50:11 +0100 2011
ruby-1.8.7-p174 > User.last.has_role! "installer"
User Load (0.5ms) SELECT * FROM "users" ORDER BY users.id DESC LIMIT 1
Country Load (0.2ms) SELECT * FROM "countries" WHERE ("countries"."id" = 106)
Role Load (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 "roles".id = "roles_users".role_id WHERE ("roles"."id" = 2) AND ("roles_users".user_id = 31 ) LIMIT 1
SQL (0.3ms) INSERT INTO "roles_users" ("created_at", "updated_at", "role_id", "user_id") VALUES ('2010-09-16 14:11:24', '2010-09-16 14:11:24', 2, 31)
Role Load (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")
Role Load (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", updated_at: "2010-09-16 14:11:24">
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
acl9 使用的 habtm 连接表可能没有附加属性。
如果在连接表中存在created_at或updated_at属性,ActiveRecord会使用关联表的值(在您的情况下为角色)填充此值。
如果您想要此功能,则必须编辑 gem 并向关系添加一些 :after_add 回调过滤器,请查看此 文件
另外,updated_at 是无用的,因为连接数据库表中的行已创建并删除,从未更新...
希望这可以有所帮助,抱歉我的英语。
the habtm join table used by acl9 might not have additional attributes.
if in the join table there'is created_at or updated_at attributes ActiveRecord populate this value with the value of associated table (Role in your case) .
If you want this functionality you have to edit the gem and add some :after_add callback filter to the relations, look at row 41 of this file
also, updated_at is useless because the row in the join db table was created and removed ,never updated...
hope this could help , sorry for my english .
这确实是由 acl9 文档中的错误引起的(因为 habtm 连接表不应该有时间戳)。我也修复了 文档,acl9 1.2 现在有一个生成器也适用于该迁移:)
This really was caused by an error in the acl9 docs (because a habtm join table shouldn't have timestamps). I fixed the docs too, and acl9 1.2 now has a generator for that migration too :)