boss_db
boss_db copied to clipboard
New From JSON does not seem to work properly
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.
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.