From b05964a466e0e16a65ed28d72090909402c7fdc3 Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Sat, 10 Dec 2016 11:38:40 -0500 Subject: [PATCH] Docs: where_object, where_object_changes --- lib/paper_trail/version_concern.rb | 49 +++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/lib/paper_trail/version_concern.rb b/lib/paper_trail/version_concern.rb index 3f67d39b..a73773c1 100644 --- a/lib/paper_trail/version_concern.rb +++ b/lib/paper_trail/version_concern.rb @@ -95,9 +95,25 @@ module PaperTrail end end - # Query the `versions.objects` column using the SQL LIKE operator. - # Performs an attribute search on the serialized object by invoking the - # identically-named method in the serializer being used. + # Given a hash of attributes like `name: 'Joan'`, query the + # `versions.objects` column. + # + # ``` + # SELECT "versions".* + # FROM "versions" + # WHERE ("versions"."object" LIKE '% + # name: Joan + # %') + # ``` + # + # This is useful for finding versions where a given attribute had a given + # value. Imagine, in the example above, that Joan had changed her name + # and we wanted to find the versions before that change. + # + # Based on the data type of the `object` column, the appropriate SQL + # operator is used. For example, a text column will use `like`, and a + # jsonb column will use `@>`. + # # @api public def where_object(args = {}) raise ArgumentError, "expected to receive a Hash" unless args.is_a?(Hash) @@ -123,8 +139,31 @@ module PaperTrail end end - # Query the `versions.object_changes` column by attributes, using the - # SQL LIKE operator. + # Given a hash of attributes like `name: 'Joan'`, query the + # `versions.objects_changes` column. + # + # ``` + # SELECT "versions".* + # FROM "versions" + # WHERE .. ("versions"."object_changes" LIKE '% + # name: + # - Joan + # %' OR "versions"."object_changes" LIKE '% + # name: + # -% + # - Joan + # %') + # ``` + # + # This is useful for finding versions immediately before and after a given + # attribute had a given value. Imagine, in the example above, that someone + # changed their name to Joan and we wanted to find the versions + # immediately before and after that change. + # + # Based on the data type of the `object` column, the appropriate SQL + # operator is used. For example, a text column will use `like`, and a + # jsonb column will use `@>`. + # # @api public def where_object_changes(args = {}) raise ArgumentError, "expected to receive a Hash" unless args.is_a?(Hash)