我有很多表,我每周都将所有字段设置为零,除了一些选择的字段(包括外键和一些时间值)。目前,我正在使用update_all(field:value,...)命令,它可以正常工作。唯一的问题是我必须列出我要清除的每个字段,而且我经常忘记在更改表时添加字段,这会导致错误。
有没有办法让rails清除表中的所有字段,除了指定的几个字段?
谢谢!
答案 0 :(得分:2)
在Rails中,每个模型都有方法<div class="column">
<div class="flex-container">
<div class="flex-item">
L1
</div>
<div class="flex-item">
L2
</div>
<div class="flex-item">
L3
</div>
<div class="flex-item">
L4
</div>
<div class="flex-item">
L5
</div>
<div class="flex-item">
L6
</div>
</div>
</div>
,它返回列的列表。你可以为每个模型做这样的事情:
tell application "Finder"
close every window
activate
open trash
select every item of trash
delay 1
end tell
tell application "System Events"
key code 51 using (command down)
delay 1
try
set theCheckbox to checkbox "Apply to All" of scroll area 1 of window "Copy" of application process "Finder"
set applyToAll to perform action "AXPress" of checkbox "Apply to All" of scroll area 1 of window "Copy" of application process "Finder"
set replaceButton to perform action "AXPress" of button "Replace" of scroll area 1 of window "Copy" of application process "Finder"
if theCheckbox exists then
delay 1
applyToAll
delay 1
replaceButton
else
key code 51 using (command down)
end if
end try
end tell