簡體   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