Error in boss_db?

23 views
Skip to first unread message

Graeme Defty

unread,
Jul 3, 2014, 10:05:07 AM7/3/14
to chica...@googlegroups.com
Another interesting one...

One of my models was returning 'undefined' in response to boss_db:find/1

I tracked it down to boss_db:find/2, part of which looks like this:

<pre>
find(Key, Timeout) when is_list(Key), is_integer(Timeout) ->
    [IdToken|Rest] = string:tokens(Key, "."),
    case db_call({find, IdToken}, Timeout) of
        undefined -> undefined;
        {error, Reason} -> {error, Reason};
        BossRecord -> BossRecord:get(string:join(Rest, "."))
    end;</pre>

For some reason the BossRecord:get call on the second last line was returning 'undefined' on one of my models. (I didnt try them all, but 8-10 others I tried were fine!)

I fixed the problem by changing the code as follows:

<pre>
find(Key, Timeout) when is_list(Key), is_integer(Timeout) ->
    [IdToken|Rest] = string:tokens(Key, "."),
    case db_call({find, IdToken}, Timeout) of
        undefined -> undefined;
        {error, Reason} -> {error, Reason};
        BossRecord ->
            case Rest of
                []    ->    BossRecord;
                _    ->    BossRecord:get(string:join(Rest, "."))
            end
    end;
</pre>


I have no idea if this is a good solution (though it looks reasonable) and I am also equally puzzled by the fact that it only happened with one of my models, but then I dont know what the 'get' function is supposed to do. Perhaps someone wiser than I . . . .


g






can2nac

unread,
Jul 4, 2014, 11:07:19 AM7/4/14
to chica...@googlegroups.com
check deeply nested values section of manual http://www.chicagoboss.org/api-record.html

get(Path::string()) -> Value

Returns a deeply nested value described by a dot-separated Path (e.g. "puppy.mother.name")

Graeme Defty

unread,
Jul 4, 2014, 11:30:47 AM7/4/14
to chica...@googlegroups.com
Ah OK Thanks.

That is a bit of functionality which has slipped by me.

I am still not sure why my one model does not like the get/1 function (and I really do not like not understanding things), but this is enough to convince me that my solution is reasonable. No sense calling the get/1 function if there is no 'Rest' part, right?

g





--
You received this message because you are subscribed to the Google Groups "ChicagoBoss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chicagoboss...@googlegroups.com.
Visit this group at http://groups.google.com/group/chicagoboss.
To view this discussion on the web visit https://groups.google.com/d/msgid/chicagoboss/7614a9a2-5337-45e5-bbf0-29d625908166%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages