Photo_78_small Kevin Smith 20 posts

Jon Gretar has pointed out an error in the refactoring of the get_messages/1 function during the screencast. When I refactored the query to return only the message bodies this had the side-effect of breaking delete_messages/1 since it depended on having a list containing entire chat_message records.

Clearly this code is broken. I should’ve tested the final version of the code before publishing the episode.I’d like to apologize for any confusion this might’ve caused. I’m working on updating the site with a fixed version of the code. For now, here’s the fixed version of the function:

get_messages(Addressee) ->
  F = fun() ->
      Query = qlc:q([M || M <- mnesia:table(chat_message),
                  M#chat_message.addressee =:= Addressee]),
      Results = qlc:e(Query),
      delete_messages(Results),
      lists:map(fun(Msg) -> Msg#chat_message.body end, Results) end,
  {atomic, Messages} = mnesia:transaction(F),
  Messages.

1 post, 1 voice