【问题标题】:Acl9 association table created_at column issueAcl9关联表created_at列问题
【发布时间】:2011-07-03 15:36:09
【问题描述】:

我试图弄清楚为什么角色_用户表的 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! “安装程序”
用户负载 (0.5ms) SELECT * FROM “用户” 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
角色加载 (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 ) 限制 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 )
=> [#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", updated_at: "2010-09 -16 14:11:24">

【问题讨论】:

    标签: ruby-on-rails activerecord acl9


    【解决方案1】:

    acl9 使用的 habtm 连接表可能没有其他属性。

    如果在连接表中有 created_at 或 updated_at 属性 ActiveRecord 使用关联表的值填充此值(在您的情况下为角色)。

    如果你想要这个功能,你必须编辑 gem 并添加一些 :after_add 回调过滤器到关系中,查看这个file的第 41 行

    另外,updated_at 是无用的,因为连接数据库表中的行被创建和删除,从未更新......

    希望这可以帮助,对不起我的英语。

    【讨论】:

      【解决方案2】:

      这确实是由 acl9 文档中的错误引起的(因为 habtm 连接表不应该有时间戳)。我也修复了the docs,acl9 1.2 现在也有一个用于该迁移的生成器:)

      【讨论】:

        猜你喜欢
        • 2012-07-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-07-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多