Skip to content

strange behavior in the "created_at" attribute of PaperTrail::Version that has the event attribute "create" #412

@izelnakri

Description

@izelnakri

Here is an example and why its kinda sucks:

  model = Model.first
  version = model.versions[0]
  record = JSON.parse(version.to_json).except("id") #It turns ActiveRecord to a hash
  #we might need this record above to sync to some other database

  version.created_at == record["created_at"] # returns FALSE!! although 
  #they both have the same string value, and case persists 
  #even if you turn them into the same class with same values (strange)

#why it is important? here is why:

 PaperTrail::Version.find_or_create_by(record)
 #This would create a new record... very strange given it just duplicates the first
 # create event trail. This weird behavior makes syncing to databases via script kinda hacky

#I need to do the following to prevent duplication for the new database:

  record = record.except("created_at") if record["event"] == "create"
  PaperTrail::Version.find_or_create_by(record)

#update events don't create this duplication I don't know the situation for the delete event trails

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions