简体   繁体   English

ACL9关联表created_at列问题

[英]Acl9 association table created_at column issue

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. 我试图弄清楚为什么在将角色分配给用户时Roles_users表的created_at列似乎使用户成为一个。 It should not have its own creation date? 它不应该有自己的创建日期吗? Any helps? 有帮助吗?

ruby-1.8.7-p174 > Time.now ruby-1.8.7-p174> Time.now
=> Thu Feb 24 15:50:11 +0100 2011 => 2011年2月24日星期四15:50:11 +0100
ruby-1.8.7-p174 > User.last.has_role! ruby-1.8.7-p174> User.last.has_role! "installer" “安装程序”
User Load (0.5ms) SELECT * FROM "users" ORDER BY users.id DESC LIMIT 1 用户负载(0.5毫秒)SELECT * FROM“ users” ORDER BY users.id DESC LIMIT 1
Country Load (0.2ms) SELECT * FROM "countries" WHERE ("countries"."id" = 106) 国家负载(0.2毫秒)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 角色负载(0.2ms)SELECT * FROM“ roles”位置(名称='安装程序'并且authorizable_type IS NULL和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 角色负载(0.1毫秒)从“角色”中选择“ roles” .id内联接“ roles_users”在“ roles” .id =“ roles_users” .role_id位置(“ 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) SQL(0.3毫秒)插入“ roles_users”(“ created_at”,“ updated_at”,“ role_id”,“ user_id”)值(' 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 ) 角色负载(0.5毫秒)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">] => [#角色ID:2,名称:“安装程序”,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") ruby-1.8.7-p174> Role.find_by_name(“安装程序”)
Role Load (0.3ms) SELECT * FROM "roles" WHERE ("roles"."name" = 'installer') LIMIT 1 角色负载(0.3毫秒)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"> =>#角色ID:2,名称:“安装程序”,authorizable_type:nil,authorizable_id:nil,created_at:“ 2010-09-16 14:11:24 ”,updated_at:“ 2010-09-16 14:11:24 “>

the habtm join table used by acl9 might not have additional attributes. acl9使用的habtm连接表可能没有其他属性。

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) . 如果在联接表中有created_at或Updated_at属性,则ActiveRecord用关联表的值(在您的情况下为Role)填充此值。

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 如果需要此功能,则必须编辑gem并在关系中添加一些:after_add回调过滤器,请查看此文件的第41行

also, updated_at is useless because the row in the join db table was created and removed ,never updated... 同样,updated_at是无用的,因为join db表中的行已创建和删除,从不更新...

hope this could help , sorry for my english . 希望能有所帮助,对不起我的英语。

This really was caused by an error in the acl9 docs (because a habtm join table shouldn't have timestamps). 这确实是由acl9文档中的错误引起的(因为habtm连接表不应包含时间戳)。 I fixed the docs too, and acl9 1.2 now has a generator for that migration too :) 我也修复了文档 ,并且acl9 1.2现在也为该迁移提供了一个生成器:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM