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

Inconsistent set via associated record name behavior with save_empty: false #30

Open
jordannb opened this issue Oct 25, 2021 · 0 comments

Comments

@jordannb
Copy link
Contributor

See tests defined here, noting that only the second one fails: jordannb@78c2e8d

For convenience, here is the failing test:

it "does save non-empty values when using assoc name" do
  e = TestClass.create!
  e.name = "TEST"
  e.no_empties_assoc.ext_field_using_empties_not_saved = "Another test"
  e.save!
  expect(NoEmptiesAssociationTestClass.count).to eq(1)
end

This fails because the empty record returned by no_empties_assoc is merely an in-memory placeholder and isn't actually associated (in ActiveRecord terms) with the parent record, e, that it "belongs" to. Data set this way will work if the :no_empties_assoc returns a non-empty value (on that is stored in the database), as this means there's an association with the parent record.

Due to the custom setters created by the ExternalFields gem, we don't actually need to set values using this mechanism at all, and the fact that it works is an undocumented behavior (note that README and existing tests suggest that e.ext_field_using_empties_not_saved = "Another test" is the way to set values, not e.no_empties_assoc.ext_field_using_empties_not_saved = "Another test". The second mechanism is redundant, undocumented, and perhaps unnecessary.

I propose we either update the behavior so that it's consistent or remove the ability to set values in this way entirely. It'd be good to consider addressing this before #29 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant