Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A tracker on an embeds_many relation is being limited by the parent configuration #244

Open
vanboom opened this issue Jun 13, 2020 · 1 comment
Labels

Comments

@vanboom
Copy link

vanboom commented Jun 13, 2020

In tracker.rb...

    def tracked_changes
        @tracked_changes ||= (modified.keys | original.keys).inject(HashWithIndifferentAccess.new) do |h, k|
          h[k] = { from: original[k], to: modified[k] }.delete_if { |_, vv| vv.nil? }
          h
        end.delete_if { |k, v| v.blank? || !trackable_parent_class.tracked?(k) }
      end

The !trackable_parent_class.tracked?(k) is causing tracked attributes on the child relation to be removed if the attribute is not whitelisted in the parent. This seems to be a logic error.

For example:

class User
   field :name
   embeds_many :posts, cascade_callbacks: true
   track_history
end
class Post
   field :body
   embedded_in :user
   track_history
end

> user.posts.first.history_tracks.first.tracked_edits 

tracked_edits returns nothing unless body is whitelisted in the parent model like this...

class User
  field :name
  embeds_many :posts, cascade_callbacks: true
  track_history on: [:body]
end

Attempting to whitelist the attribute for the embedded child does not work...

class User
  field :name
  embeds_many :posts, cascade_callbacks: true
  track_history on: [:body, posts: [:body]]
end
vanboom added a commit to vanboom/mongoid-history that referenced this issue Jun 13, 2020
@dblock
Copy link
Collaborator

dblock commented Jun 14, 2020

This exists for a reason I am sure, but will need a closer look. PR a fix with some specs and let's see what existing specs fail?

@dblock dblock added the bug? label Jun 14, 2020
vanboom added a commit to vanboom/mongoid-history that referenced this issue Jul 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants