Skip to content

Instantly share code, notes, and snippets.

@stochastic-thread
Created July 25, 2015 00:48
Show Gist options
  • Save stochastic-thread/7b3e38bdcbbe6c0a956e to your computer and use it in GitHub Desktop.
Save stochastic-thread/7b3e38bdcbbe6c0a956e to your computer and use it in GitHub Desktop.
OrderItem quantity error
[error] #PID<0.620.0> running Trophus.Endpoint terminated
Server: 127.0.0.1:4000 (http)
Request: POST /add_to_cart
** (exit) an exception was raised:
** (ArgumentError) unknown field `quantity` (note only fields are supported in cast, associations are not)
(ecto) lib/ecto/changeset.ex:248: Ecto.Changeset.type!/2
(ecto) lib/ecto/changeset.ex:231: Ecto.Changeset.process_param/6
(elixir) lib/enum.ex:1100: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
(ecto) lib/ecto/changeset.ex:216: Ecto.Changeset.cast/4
(trophus) web/controllers/cart_controller.ex:56: Trophus.CartController.add_to_cart/2
(trophus) web/controllers/cart_controller.ex:1: Trophus.CartController.phoenix_controller_pipeline/2
(trophus) lib/phoenix/router.ex:281: Trophus.Router.dispatch/2
(trophus) web/router.ex:1: Trophus.Router.do_call/2
defmodule Trophus.OrderItem do
use Trophus.Web, :model
schema "order_items" do
belongs_to :dish, Trophus.Dish, foreign_key: :dish_id
belongs_to :order, Trophus.Order, foreign_key: :order_id
field :quantity, :integer
field :total_price, :integer
field :unit_price, :integer
timestamps
end
@required_fields ~w()
@optional_fields ~w(quantity total_price unit_price)
@doc """
Creates a changeset based on the `model` and `params`.
If no params are provided, an invalid changeset is returned
with no validation performed.
"""
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