Browse Source

Support Ecto belongs_to and has_one associations

Evan Miller 11 years ago
parent
commit
c28fb798c7
1 changed files with 9 additions and 1 deletions
  1. 9 1
      src/erlydtl_runtime.erl

+ 9 - 1
src/erlydtl_runtime.erl

@@ -45,7 +45,15 @@ find_value(Key, Tuple) when is_tuple(Tuple) ->
         Module ->
             case lists:member({Key, 1}, Module:module_info(exports)) of
                 true ->
-                    Tuple:Key();
+                    case Tuple:Key() of
+                        Val when is_tuple(Val) ->
+                            case element(1, Val) of
+                                'Elixir.Ecto.Associations.BelongsTo' -> Val:get();
+                                'Elixir.Ecto.Associations.HasOne' -> Val:get();
+                                _ -> Val
+                            end;
+                        Val -> Val
+                    end;
                 _ ->
                     undefined
             end