简体   繁体   English

如何将Rails复杂对象上的红宝石转储到磁盘,以便可以将该对象加载到其他数据库中

[英]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.

相关问题 如何在Ruby on Rails中将子对象添加到父对象 - How do I add child object to parent object in Ruby on Rails 如何在Rails 3上使用ruby获取带有其他参数的请求对象? - How do I get request object with other params using ruby on rails 3? 如何将 Ruby 脚本与 object 关联并按需执行(在 Rails 中)? - How do I associate a Ruby script with an object and execute it on demand (in Rails)? 如何在Rails中获取mb中ruby对象的大小? - How do I get the size of a ruby object in mb in Rails? 如何在Ruby on Rails中使对象成为模型的属性? - How do I make an object a property of a model in Ruby on Rails? 如何从我的 Ruby on Rails API 解析这些哈希转换为字符串,以便它可以作为 object 在 Z9E1713B69D1D24ADA9 中访问 - How can I parse these hashes turned string, from my Ruby on Rails API so that it's accessible as an object in Javascript? 如何在Ruby on Rails的会话对象中显示值? - How can i display values in session object in Ruby on Rails? 如何在 ruby​​ on rails 2 中检查对象是否为空? - How I can check if an object is null in ruby on rails 2? 如何在Ruby on Rails中进行查询以过滤对象的对象是否为nil - How do I make a query in Ruby on Rails to filter if an object's object's object is nil 如何在Rails中通过ID以外的属性查找对象? - How can I find object by an attribute other than id in Rails?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM