bullet-train-pro / bullet_train-action_models

Other
5 stars 1 forks source link

[Accounts] ACC-156 - Step 1 - Pass AR object to mark row processed #39

Closed phillipn closed 1 year ago

phillipn commented 1 year ago

This needs to be merged before we can merge https://github.com/clickfunnels2/admin/pull/15864.

I have a PR where I want to do something after each row gets processed. Specifically, I want to create a Contact::AppliedTag record after each row is successfully uploaded.

I originally thought after_each was the go-to method. However, this method runs after every record gets processed, whether it is successful or not.

So there are two changes here:

  1. mark_row_processed was renamed to after_row_processed
  2. We are passing an active record object to the method, so that we can use it to do more things, like creating an associated AR object. For instance, here is my override that I will include in a PR to create a Tag on row create:

    def after_row_processed(record)
    super
    
    record.applied_tags.create(tag: tag)
    end