administrate-field-nested_has_many icon indicating copy to clipboard operation
administrate-field-nested_has_many copied to clipboard

ar_lazy_preload gem breaks functionality

Open HuntBurdick opened this issue 1 year ago • 3 comments

I had an issue where in progress form values were lost on validation failures for existing records. It was strange because it worked as expected and persisted in progress values for new records but not existing ones. I spent quite a while debugging this gem and banging my head until I realized it was an unrelated gem ar_lazy_preload interfering with the loading of associations. This line in particular was the culprit ArLazyPreload.config.auto_preload = true.

There is probably a way to make it play nice but I'm just disabling the ar_lazy_preload for administrate for now. This is not an issue with the administrate-field-nested_has_many gem but I did want to make note of it here and ask if a documentation PR would be helpful to help others avoid the pitfall? I have no idea how popular the ar_lazy_preload gem is but I've found it very helpful in the past.

HuntBurdick avatar Feb 14 '24 12:02 HuntBurdick

Do you know if it's specifically a problem with this field, or Administrate more broadly? I'd be tempted to highlight it in Administrate itself, perhaps somewhere in the guides.

Unless there's something this gem (or Administrate itself) could implement better, that's likely all we should do. I've not heard on ar_lazy_preload, but that's not saying much 😅

nickcharlton avatar Feb 14 '24 15:02 nickcharlton

I do not believe this affects anything in Administrate itself or at least I have not observed it doing so. Granted, I am not using the has_many field from Administrate anywhere and mainly relying on this gem for nested associations. It is possible that this does affect the has_many or other fields. I'll give it shot when I get a chance but as far as I know this only affects this gem.

What the ar_lazy_preload gem does is lazily load associations to avoid n+1 queries, which is particularly useful when optimizing greedy GraphQL calls. It is possible that other preloading strategies even outside of the ar_lazy_preload could also break the functionality but I'm just speculating there.

HuntBurdick avatar Feb 14 '24 15:02 HuntBurdick

Cool, thanks! If it is indeed specific to this, it might be worth having a line in this project's README to point it out.

nickcharlton avatar Feb 14 '24 15:02 nickcharlton