Skip to content

Commit

Permalink
Document another way to build derived attributes (#449)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanl authored Jun 24, 2024
1 parent a4352dd commit 88c6450
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,16 @@ defmodule MyApp.Factory do
%MyApp.Article{
title: title,
slug: slug,
# another way to build derived attributes
tags: fn article ->
if String.contains?(article.title, "Silly") do
["silly"]
else
[]
end
end,
# associations are inserted when you call `insert`
author: build(:user),
author: build(:user)
}
end

Expand Down

0 comments on commit 88c6450

Please sign in to comment.