gpt4 book ai didi

ruby - 纸迹 gem : How to use a custom item_type for specific model

转载 作者:太空宇宙 更新时间:2023-11-03 16:59:03 28 4
gpt4 key购买 nike

是否有为版本配置 item_type 的选项?我有一个 Post 类,默认的 item_type 是 Post;是否有配置为 Foo 的选项?

示例更新:

class Post < ActiveRecord::Base
has_paper_trail
end

post = Post.create # this creates a new post along with a version.
version = post.versions.first
version.item_type = 'Post' # Item type here is the name of the base model 'Post'.

最佳答案

Is there an option to configure the item_type for a version? I have a class Post, and the default item_type for that would be Post; is there an option to configure that be Foo?

没有。当您调用 has_paper_trail 时,它会添加一个名为 item 的多态关联。因此,PaperTrail 不控制数据库列 item_type,ActiveRecord 控制。

下面是 has_many 关联的定义:

has_many(
versions_association_name, # Usually "versions"
-> { order(model.timestamp_sort_order) }, # Usually "created_at"
class_name: version_class_name, # Usually "PaperTrail::Version"
as: :item # Specifies a polymorphic interface
)

关于ruby - 纸迹 gem : How to use a custom item_type for specific model,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37175689/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com