Ruby on Rails,habtm收集方法不收集?
我正在尝试在删除时将数据备份到 yaml 存储,如下所示:
DeleteProject.create!(:data => {
:project => project.attributes,
:domains => project.domains.collect(&:attributes),
:databases => project.databases.collect(&:attributes)
}.to_yaml)
但是,尽管项目和域数据存储良好,但数据库始终返回空白。该关系是通过
- has_and_belongs_to_many :databases
- has_and_belongs_to_many :projects
完成的我对此陷入了死胡同,因为我不知道为什么它根本不会传递当前数据来自项目.数据库。任何见解都会很棒,谢谢!
I am trying to backup data to a yaml store on deletion like so:
DeleteProject.create!(:data => {
:project => project.attributes,
:domains => project.domains.collect(&:attributes),
:databases => project.databases.collect(&:attributes)
}.to_yaml)
However although the project and domain data is stored fine, databases is always coming back blank. The relationship is done via
- has_and_belongs_to_many :databases
- has_and_belongs_to_many :projects
I am at a dead end with this one as I do not know why it simply would not be passing in the current data from project.databases. Any insight would be great, thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,我通过执行以下操作解决了这个问题:
:database_connections
更新模型以使用 has_many,然后更新连接表,不再是database_projects,而是database_connections。
Okay so I fixed this by doing the following:
:database_connections
Updated models to use has_many and then updated the connecting table no longer database_projects but database_connections.