【文件属性】:
文件名称:mover:跨表移动ActiveRecord记录不是这样
文件大小:15KB
文件格式:ZIP
更新时间:2021-05-15 01:44:25
Ruby
移动器
跨表移动ActiveRecord记录并不是一件容易的事。
要求
sudo gem install mover
移动记录
移动上一篇文章:
Article.last.move_to(ArticleArchive)
移动今天的文章:
Article.move_to(
ArticleArchive,
:conditions => [ "created_at > ?", Date.today ]
)
这两个表不必相同。 仅共享列传输。
如果发生主键冲突,那么将更新目标记录。
回呼
在此示例中,我们需要一个用于文章和评论的“存档”表。
我们还希望在发表文章时将其评论存档。
class Article < ActiveRecord::Base
has_many :comments
before_move :ArticleArchive do
comments.
【文件预览】:
mover-master
----config()
--------gemspec.yml(347B)
--------gemsets.yml(75B)
----Rakefile(2KB)
----LICENSE(1KB)
----init.rb(46B)
----spec()
--------config()
--------db()
--------Rakefile(226B)
--------mover()
--------mover_spec.rb(4KB)
--------spec_helper.rb(1KB)
--------fixtures()
----.gitignore(66B)
----mover.gemspec(1KB)
----lib()
--------mover()
--------mover.rb(5KB)
----README.md(2KB)
----rails()
--------init.rb(66B)