On Sunday, June 28, 2020 at 7:28:37 AM UTC-7, Aryk Grosz wrote:
>
> Currently for the composition plugin, if you set a composed argument, it
> will not get decomposed until before_validation:
>
> def before_validation
> # decomposer_method is private
> @compositions.keys.each{|n|
> send(model.compositions[n][:decomposer_method])} if @compositions
> super
> end
>
>
> Any reason this is hard coded in place?
>
> If you use FactoryBot for instance, and you want to do
> build(:record_name), the composed fields will not be decomposed into their
> attributes unless you just randomly run "valid?" on it.
>
save runs validation hooks by default, so assuming it runs save,
decomposition should also happen then. Not sure what FactoryBot does when
you run build. In general you only need to decompose attributes when
saving, there is no need if you are not saving. Unless you are doing
something like also checking the decomposed values (in which case, why use
a composition)?
> Seems like there should be a way to call it ahead of time if needed or
> change where it happens.
>
> Maybe a "decompose_compositions" function that one could call directly?
>
Sure, it's possible to extract a method for reuse, it's just that nobody
has asked for it yet. Feel free to send in a pull request with specs if
you would like it extracted.
Thanks,
Jeremy
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sequel-talk/6451940b-b2a4-4ebb-919d-fcbd13ad9f2co%40googlegroups.com.