paper_trail icon indicating copy to clipboard operation
paper_trail copied to clipboard

Is there a way to pass originator_id instead of originator struct?

Open rlopzc opened this issue 3 years ago • 1 comments

First off, nice repo very helpful!

Use case: I have the user_id inside a Merchant struct (belongs_to) and most of the times the user isn't loaded but I do have the originator_id (user_id) available. It would be better to not preload an association that is only going to use the .id when passing the originator: struct

rlopzc avatar Jul 06 '21 14:07 rlopzc

Hi @romariolopezc , sorry for late response, summer times ;)

originator supposed to be "the person who does the action" so if the web request is fired by a certain individual, you should already have the person available within that request. However a developer should be able to insert a new PaperTrail.Version by just just providing originator_id instead of originator during PaperTrail.insert or update or delete, you are indeed right this might not be supported currently: https://github.com/izelnakri/paper_trail/blob/main/lib/paper_trail/serializer.ex#L27

I'm willing to merge a PR that includes this functionality if one provides with a test.

izelnakri avatar Jul 28 '21 00:07 izelnakri

It looks like it is possible to pass a map with only the originator ID instead of the whole struct like originator: %{id: id}.

You can see it here -> https://github.com/izelnakri/paper_trail/blob/main/lib/paper_trail/serializer.ex#L26

jkmrto avatar Oct 05 '22 11:10 jkmrto

as @jkmrto pointed out, this feature is currently possible, thus I'm closing this issue. Please let me know if you'd like it to be reopened @rlopzc !

izelnakri avatar Oct 06 '22 08:10 izelnakri