Last active
January 12, 2017 22:14
-
-
Save alduro/027dc9c7104b03be74986faec2961210 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def render("product.json", %{product: product}) do | |
%{id: product.id, | |
name: product.name, | |
description: product.description, | |
price: product.price} | |
|> add_options(product) | |
end | |
defp add_options(json, %{product: product}) do | |
options = | |
product | |
|> ExRushlookApi.Repo.preload(:options) | |
|> render_many(ExRushlookApi.OptionView, "show.json") | |
Map.put(json, :options, options) | |
end | |
defp add_options(json, _product) do | |
json | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment