boss_db icon indicating copy to clipboard operation
boss_db copied to clipboard

New From JSON does not seem to work properly

Open DrAlexMV opened this issue 11 years ago • 1 comments

The current implementation of new_from_json does not seem to work for me:

new_from_json(Model, JSON) ->
    DummyRecord = boss_record_lib:dummy_record(Model),
    Attributes  = DummyRecord:attribute_names(),
    Set         = set_attribute(_, [{id, id}] ++ JSON, _),
    lists:foldl(Set, DummyRecord, Attributes).

Changing it to:

new_from_json(Model, JSON) ->
    DummyRecord = boss_record_lib:dummy_record(Model),
    Attributes  = DummyRecord:attribute_names(),
    Set         = set_attribute(_, [{<<"id">>, id}] ++ JSON, _),
    lists:foldl(Set, DummyRecord, Attributes).

Fixes the issues with it not being able to read the id field.

DrAlexMV avatar Aug 08 '14 04:08 DrAlexMV

I came across the same problem and solution. The id must be in binary because the proplists:get_value below looks for binary values of attributes and without this the attribute gets set to null.

jitinl avatar Sep 25 '14 13:09 jitinl