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

Fix populator bug causing new data to never be set. #198

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

undergroundwebdesigns
Copy link

Currently, the populator is coded to remove the SetValue operation from the pipeline, and in my testing this means that the populator runs and returns the correct record (e.g. via the "find or instantiate" logic), but then new values from the are never set on that record.

In my testing, simply dropping this line makes everything work as expected.

I do see that Representable::FindOrInstantiate is coded to set it's result object on the represented object directly, so maybe I'm misunderstanding something about how populators are supposed to work? As currently coded, how are the input values ever going to be set on the populated object?

@undergroundwebdesigns
Copy link
Author

undergroundwebdesigns commented Oct 13, 2016

Note: I also dropped the "setter" lines from the Representable::FindOrInstantiate lambda, as they seem to now be redundant and caused the value to be set twice. Usually this isn't a problem, but in certain cases with rails "has and belongs to many through" relations, setting the relation the second time causes an undesired DB save ¯_(ツ)_/¯ (Rails, why you do dis!?!)

@apotonick
Copy link
Member

The input values in the nested fragment are set after the populator. The latter creates/finds the nested object, appends it to the parent object (and you're right, I am confused now, too, about why you could simply remove that block), and then calls from_json for the representer corresponding to the nested fragment.

@undergroundwebdesigns
Copy link
Author

Well, if we're both confused, maybe some more research is needed into what's going on here? I can confirm the above fix works, we've been using it in production on a rather large app for a couple months now...

@apotonick
Copy link
Member

Thanks Alex, I am about to dive into making Reform's and Representable's populators do the same thing, I'll let you know about my findings. Thanks for pointing this out!!!

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

Successfully merging this pull request may close these issues.

2 participants