Skip to content

Instantly share code, notes, and snippets.

@talum
Created September 6, 2017 03:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save talum/dfafc3342b0751551957f021214fc611 to your computer and use it in GitHub Desktop.
Save talum/dfafc3342b0751551957f021214fc611 to your computer and use it in GitHub Desktop.
programming phoenix ch 9

Programming Phoenix: Chapter 9

Brunch

  • build tool
  • interface for player

Changeset Benefits

  • separate policy for each type of change
  • filter / cast incoming data
  • validate data (length or format)
  • composable

Extending Phoenix with Protocols

  • Phoenix defines protocol Phoenix.Param, which extracts id of struct if exists
  • Elixir protocols can be implemented for any data structure anywhere
  • "overwriting" the to_param function to customize it for path helper

Extending Schemas with Ecto Types

  • custom type, allows you to associate some behavior to id fields
  • custom type defined according to Ecto.Type behavior
  • expects you to define four functions:
    • type: underlying ecto type
    • cast: called when external data passed into Ecto
    • dump: invoked when data sent to db
    • load: invoked when data loaded
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment