Acl9关联表created_at列问题

发布于 2024-10-19 07:51:13 字数 1466 浏览 3 评论 0原文

我试图弄清楚为什么在为用户分配角色时,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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

德意的啸 2024-10-26 07:51:13

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 .

莫相离 2024-10-26 07:51:13

这确实是由 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 :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文