ErlyORM / boss_db

BossDB: a sharded, caching, pooling, evented ORM for Erlang
Other
277 stars 138 forks source link

New From JSON does not seem to work properly #193

Open DrAlexMV opened 10 years ago

DrAlexMV commented 10 years ago

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.

jitinl commented 10 years ago

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.