在 Rails Migration 中触发删除查询的更好方法是什么
我对 Rails 有点陌生,我想写一些 self.down 查询。目前我正在对整个查询进行硬编码。有更简单的方法吗?
def self.down
delete("delete from trigger_events where name = 'CHANGE_APPROVED'")
delete("delete from notifications where trigger_event_id = 5")
delete("delete from notification_recipients where notification_id = 5")
delete("delete from n_m_d where notification_id = 5 and msg_index=15")
end
谢谢
I am kind of new to Rails and I want to write some self.down queries. Currently I am hardcoding the entire query. Is there a easier way to do it ?
def self.down
delete("delete from trigger_events where name = 'CHANGE_APPROVED'")
delete("delete from notifications where trigger_event_id = 5")
delete("delete from notification_recipients where notification_id = 5")
delete("delete from n_m_d where notification_id = 5 and msg_index=15")
end
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以用 ActiveRecord 风格来做到这一点:
You can do that in ActiveRecord style :
根据@shingara,但进行了修改以处理未找到的情况
As per @shingara but modified to deal with not found cases