繁体   English   中英

如果新的活动记录具有属性,则创建一个 has_many 关联

[英]If new active record has attributes, then create a has_many association

我有一个DoSomething model。 这个 model 允许超级用户告诉其他用户在某个时间做某事。

我想允许超级用户发送或者:

  1. 提醒其他用户在DoSomething前 30 分钟做DoSomething
  2. 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM