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

-- 
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 [email protected].
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/CAKF5fiDQNSuz%2BCQ3AqESr-ed%2BUPW-8mr0xDjx1LkdCceCpm2bA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to