[英]How do I dump a ruby on rails complex object to disk so that I can load that object into other data bases
I need to share an object (which has very complex relationships with other objects) between 2 or 3 completely separate sql databases. 我需要在2个或3个完全独立的sql数据库之间共享一个对象(与其他对象具有非常复杂的关系)。 Ideally I'd like to have a script which is scripts/dump_object class_name object_id > file and script/load_object file.
理想情况下,我想要一个脚本,该脚本为scripts / dump_object class_name object_id> file和script / load_object file。
I've tried yaml_db (which dumps the whole db - which is not optimal) and it dies with foreign key constraint errors. 我试过了yaml_db(转储整个数据库-这不是最佳选择),它死于外键约束错误。 I've tried to script this up myself by using reflections to traverse the model relationships but have gotten bogged down in trying to figure out in what order to create the objects when loading.
我试图通过使用反射遍历模型关系来编写脚本,但是陷入了试图找出加载时创建对象的顺序的困惑。
Since it appears that a programatic solution to this is possible, I'm shocked that I can't either find a snippet or a download that already does it. 由于似乎可以通过编程的方式解决此问题,因此我很震惊,因为我既找不到片段也无法找到已经完成的下载。 Anybody run across this already?
有人碰过这个吗?
You can have a look at deep cloning plugin source code(which looks fairly simple) to have an idea how to make the script yourself. 您可以看一下深度克隆插件源代码(看起来很简单),以了解如何自己制作脚本。 Typically you will need to get the object and all associations you want then do a yaml dump, then you can share your code :P
通常,您将需要获取对象和所需的所有关联,然后进行yaml转储,然后才能共享代码:P
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.