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

Fix duping for AR KeyValue backend #126

Merged
merged 1 commit into from Dec 3, 2017

Conversation

Projects
None yet
1 participant
@shioyama
Owner

shioyama commented Dec 3, 2017

Fixes #123

super(source)
self.send("#{association_name}=", source.send(association_name).map(&:dup))
# Set inverse on associations
send(association_name).each { |translation| translation.translatable = self }

This comment has been minimized.

@shioyama

shioyama Dec 3, 2017

Owner

If I leave out the spec checking that changing the attribute on one instance does not affect the value on the other instance, then this can be simplified to just:

define_method :initialize_dup do |source|
  super(source)
  self.send("#{association_name}=", source.send(association_name))
end

i.e. you don't need to dup the association objects, nor set the inverse.

However, I personally think that it's better that the dup'ed instance does not affect the original and vice versa. However, Sequel (for example) does not "deep dup" for any pattern here used in the backends... I suppose because there's a performance cost, and Sequel always defaults to not incurring any performance costs.

@shioyama

shioyama Dec 3, 2017

Owner

If I leave out the spec checking that changing the attribute on one instance does not affect the value on the other instance, then this can be simplified to just:

define_method :initialize_dup do |source|
  super(source)
  self.send("#{association_name}=", source.send(association_name))
end

i.e. you don't need to dup the association objects, nor set the inverse.

However, I personally think that it's better that the dup'ed instance does not affect the original and vice versa. However, Sequel (for example) does not "deep dup" for any pattern here used in the backends... I suppose because there's a performance cost, and Sequel always defaults to not incurring any performance costs.

This comment has been minimized.

@shioyama

shioyama Dec 3, 2017

Owner

Never mind, we definitely want duplicate models to have their own translations with AR at least. I think this is the correct way to fix this.

@shioyama

shioyama Dec 3, 2017

Owner

Never mind, we definitely want duplicate models to have their own translations with AR at least. I think this is the correct way to fix this.

@shioyama shioyama merged commit 1b14fe6 into master Dec 3, 2017

3 checks passed

codeclimate All good!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@shioyama shioyama deleted the ar_key_value_dup branch Dec 4, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment