Created
January 5, 2016 21:00
-
-
Save cjbell/50d4f10d7c6f747596cd 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
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