为ActiveRecord模型创建/保存提取生成的sql

时间:2021-07-17 09:50:07

The operations department doesn't allow migrations in production. I now have the need to supply the sql statements to insert some records -- I know it's possible to call 'to_sql', with arel, and extract the sql from finders.

运营部门不允许在生产中进行迁移。我现在需要提供sql语句来插入一些记录 - 我知道可以使用arel调用'to_sql',并从finder中提取sql。

Is there a way to do the same for 'create/save'?

有没有办法为'创建/保存'做同样的事情?

1 个解决方案

#1


1  

What about writing a unit test to do the action you require, then looking at the test.log file in your project?

如何编写单元测试来执行所需的操作,然后查看项目中的test.log文件?

(I'm assuming you're using Rails!)

(我假设你正在使用Rails!)

I did a similar thing when debugging a problem I had last night:

在调试我昨晚遇到的问题时,我做了类似的事情:

Updating ActiveRecord in Rails test

在Rails测试中更新ActiveRecord

Stu

#1


1  

What about writing a unit test to do the action you require, then looking at the test.log file in your project?

如何编写单元测试来执行所需的操作,然后查看项目中的test.log文件?

(I'm assuming you're using Rails!)

(我假设你正在使用Rails!)

I did a similar thing when debugging a problem I had last night:

在调试我昨晚遇到的问题时,我做了类似的事情:

Updating ActiveRecord in Rails test

在Rails测试中更新ActiveRecord

Stu