Skip to content

Instantly share code, notes, and snippets.

@cjbell
Created January 5, 2016 21:00
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 cjbell/50d4f10d7c6f747596cd to your computer and use it in GitHub Desktop.
Save cjbell/50d4f10d7c6f747596cd to your computer and use it in GitHub Desktop.
defmodule Shop.Order do
use Shop.Web, :model
schema "orders" do
field :email, :string
has_one :address, Shop.Address
timestamps
end
@required_fields ~w(email)
@optional_fields ~w(shipping_address)
def changeset(model, params \\ :empty) do
model |> cast(params, @required_fields, @optional_fields)
end
end
defmodule Shop.Address do
use Shop.Web, :model
schema "addresses" do
field :firstname, :string
field :lastname, :string
field :address1, :string
field :address2, :string
field :city, :string
field :postal_code, :string
field :state_name, :string
field :phone, :string
field :country, :string
belongs_to :order, Shop.Order
timestamps
end
@required_fields ~w(firstname lastname address1 city postal_code state_name country)
@optional_fields ~w(phone address2)
def changeset(model, params \\ :empty) do
model |> cast(params, @required_fields, @optional_fields)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment