[英]If new active record has attributes, then create a has_many association
我有一个DoSomething
model。 这个 model 允许超级用户告诉其他用户在某个时间做某事。
我想允许超级用户发送或者:
DoSomething
前 30 分钟做DoSomething
DoSomething
2 小时后提醒其他用户执行DoSomething
。 在DoSomething
model 上,我有用于提醒的布尔值。
创建DoSomething
后,我想检查任一提醒是否为真,如果是,请从DoSomething
model 发送提醒。
我想知道检查每个提醒然后创建提醒的机制。 提醒将是DoSomething
model 上的 has_many 关系。
如果您只关心在创建 DoSomething 时创建提醒,那么以下应该可以工作:
class DoSomething < ApplicationRecord
has_many :reminders
before_create :issue_reminders_if_needed
private
def issue_reminders_if_needed
return unless boolean_1 || boolean_2
# Code to create reminders goes here
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.