From 1af194ea466fe61e49912bbeed36cc65e4dc0c42 Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Mon, 18 Dec 2023 15:56:54 +0100 Subject: [PATCH] Try to clarify how Active Job support works under the hood --- README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2be54fc..dbadcbb 100644 --- a/README.md +++ b/README.md @@ -146,9 +146,7 @@ end ### Active Job integration via GlobalID -Because `Post.find(1)` returns a unique `Post`, we can and have added `Post.find(1).publisher` or `Post::Publisher.find(1)` to return a unique publisher. - -With this, we can implement `GlobalID::Identification` and have automatic Active Job support: +Associated Objects include `GlobalID::Identification` and have automatic Active Job serialization support that looks like this: ```ruby class Post::Publisher < ActiveRecord::AssociatedObject @@ -166,6 +164,11 @@ class Post::Publisher < ActiveRecord::AssociatedObject end ``` +> [!NOTE] +> Internally, Active Job serializes Active Records as GlobalIDs. Active Record also includes `GlobalID::Identification`, which requires the `find` and `where(id:)` class methods. +> +> We've added `Post::Publisher.find` & `Post::Publisher.where(id:)` that calls `Post.find(id).publisher` and `Post.where(id:).map(&:publisher)` respectively. + This pattern of a job `perform` consisting of calling an instance method on a sole domain object is ripe for a convention, here's how to do that. #### Remove Active Job boilerplate with `performs`