baibaratsky / yii2-serialized-attributes-behavior

ActiveRecord behavior that allows you to store arrays in attributes
Other
11 stars 7 forks source link

Preserve Order after Deserialization #6

Open rebeceva opened 6 years ago

rebeceva commented 6 years ago

Hello,

I have 2 models. One called Hotel and one called Amenities. In model Hotel I have a multiple select field of amenities. When I change the order, it's saved in the database for example :

a:9:{ i:0;s:2:"30"; i:1;s:2:"31"; i:2;s:2:"33"; i:3;s:2:"27"; i:4;s:2:"35"; i:5;s:2:"40"; i:6;s:2:"34"; i:7;s:2:"42"; i:8;s:2:"43"; } But when I use the deserialized attribute, the array is ordered by ID so It'll be : Array => [ [0] => [27] [1] => [30] [2] => [31] [3] => [33] [4] => [34] [5] => [35] ]..... How can I preserve the order after a deserialized attribute ?

Thank you for your help, Rebecca

baibaratsky commented 6 years ago

Looks like it’s a PHP serialization issue, so I think you have to find another way to store your data, not a simple array.