简体   繁体   English

强制插入纸迹

[英]Force insert in paper trail

Is it possible to force an insert in paper trail table 'versions' without making the insert in the real table. 是否可以在纸笔拖数表“版本”中强制插入而不在真实表中插入。 I need to store a 'create' insert in the paper trails table so I can get the object after a confirmation, and just then, make the real insert. 我需要在纸迹表中存储一个“创建”插入物,以便在确认后可以得到对象,然后进行真正的插入。

Thanks 谢谢

PaperTrail::Versions are just ActiveRecord objects, so you can instantiate and save them just like any of your models: PaperTrail :: Versions只是ActiveRecord对象,因此您可以像任何模型一样实例化并保存它们:

version = PaperTrail::Version.new
version.item = my_item
version.object = my_item
version.event = :create
version.save!

PaperTrail cannot store unsaved objects in its object column, however - it gets saved as nil. PaperTrail无法将未保存的对象存储在其object列中,但是-它保存为nil。 This means that .object will be nil if you load this version record out of the DB. 这意味着如果从数据库中加载此版本记录,则.object将为nil

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

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