Browse files

core: revert m_category:id_to_name/2.

Added doc explaining the use for id_to_name/2 with a name as input (thanks Arjan).
  • Loading branch information...
1 parent 6ae5cc5 commit 98a4f9184efea014b711583a886cdad9310a6dbc @kaos kaos committed Nov 13, 2012
Showing with 9 additions and 1 deletion.
  1. +9 −1 src/models/m_category.erl
10 src/models/m_category.erl
@@ -224,9 +224,17 @@ name_to_id_check(Name, Context) ->
{ok, Id} = name_to_id(Name, Context),
+%% @doc Return the name for a given category.
+%% If the category does not have a unique name will result in undefined.
+%% If the lookup is made by name, the name is checked for existence,
+%% and if not found, results in undefined.
+-spec id_to_name(Id::integer(), #context{}) -> atom() | undefined;
+ (Name, #context{}) -> atom() | undefined when Name :: atom() | binary() | list().
id_to_name(Name, Context) when is_atom(Name); is_binary(Name); is_list(Name) ->
F = fun() ->
- z_convert:to_atom(Name)
+ Nm = z_db:q1("select from rsc r join category c on = where = $1", [Name], Context),
+ z_convert:to_atom(Nm)
z_depcache:memo(F, {category_id_to_name, Name}, ?WEEK, [category], Context);
id_to_name(Id, Context) when is_integer(Id) ->

1 comment on commit 98a4f91

Zotonic member


I couldn't get edoc to properly show the spec for this function (that is, to include both versions in the docs). It only shows the first spec, so I opted for the "standard" variant, leaving the alternative in the desc only... :/

Please sign in to comment.