#1 December 15, 2016 11:03am

jmason03
Member
Registered: January 9, 2014
Posts: 123

One-To-Many JSON Saving Error

I'm having an issue when saving my one to many fields. Under normal circumstances when I save the field the data is stored in the database like this: ["3713","27","111"] which is what I believe is supposed to happen and works well. However, when I go in and either rearrange the items or delete an item that is not the first or last item, or add an item somewhere between the first and last (basically anytime I do something to change the indexed position of the existing elements) the data is getting saved in the database like this: {"1":"27","0":"3713","2":"111"}

In this example I just moved the 3713 item from first position to second position. Now after I do this, if I go back into that module entry all the data loads and my previous changes are correctly shown, everything is as it should be. But when I'm trying to pull the data for my front-end pages, I'm having to write code to account for both variations of how the data could be in the database. If I were to Save & Publish that module entry when it had the data as: {"1":"27","0":"3713","2":"111"} already and I didn't make any changes to it, it would convert it to this: ["27","3713","111"], which makes me think that the other version shouldn't actually ever exist.

Is this expected behavior or is there something off in the processing of one-to-many fields? This problem also appears to exist in the BTX Form Builder as well.

Thanks

Offline

#2 February 24, 2017 1:20pm

timbuckingham
Administrator
From: Baltimore, MD
Registered: April 2, 2012
Posts: 974

Re: One-To-Many JSON Saving Error

I'm a little embarrassed by how long it took me to respond to this -- I'm super sorry! I just pushed a fix to the core that should make it so that one-to-many fields always save as an array rather than an object.

Where were you seeing the behavior in Form Builder (if you remember after all this time!)?

Offline

Board footer

Powered by FluxBB

The Discussion Forum is not available on displays of this size.