Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New From JSON does not seem to work properly #193

Open
DrAlexMV opened this issue Aug 8, 2014 · 1 comment
Open

New From JSON does not seem to work properly #193

DrAlexMV opened this issue Aug 8, 2014 · 1 comment

Comments

@DrAlexMV
Copy link

DrAlexMV commented Aug 8, 2014

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
Copy link

jitinl commented Sep 25, 2014

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants