I've a table called Leads. It stores items such as name, quote_amount, lead_source_id and specifications.
My current update method:
def update(conn, %{"id" => _id, "data" => data} = params, user) do
#data has structure like this: data["attributes"][value_to be stored]
#Example: data["attributes"]["specifications"] for specifications value
lead =
Lead.leads(user)
|> Lead.with_id(params)
|> Repo.one!()
attrs = JaSerializer.Params.to_attributes(data)
attrs = conversion_of_company_id_param_if_necessary(attrs, Map.get(attrs, "company_id"), lead)
changeset = Lead.changeset(lead, attrs, user)
case Repo.update(changeset) do
{:ok, lead} ->
lead = Repo.get_by(Lead, id: lead.id) |> Repo.preload([:zipcode])
render(conn, "show.json-api", data: lead)
{:error, changeset} ->
conn
|> put_status(:unprocessable_entity)
|> render(PortalApi.ChangesetView, "error.json", changeset: changeset)
end
end
schema "leads" do
field(:first_name, :string)
field(:last_name, :string)
field(:email, :string)
field(:next_step, :string)
field(:activity_date, :date)
field(:phone, :string)
field(:quote_number, :string)
field(:quote_amount, :integer)
field(:po_number, :string)
field(:po_amount, :integer)
field(:closed_reason, :string)
field(:specifications,:string)
field(:zip, :string, virtual: true)
field(:local_dealer, :boolean, default: false)
field(:claimed, :boolean, default: false)
field(:state, :string, default: "new")
field(:message, :string)
field(:uuid, :string)
field(:reference_number, :string)
field(:business_name, :string)
field(:project_reference, :string)
field(:quotable, :boolean, default: false)
field(:lead_url, :string)
field(:lead_details, :string)
field(:details, :map)
field(:printed, :boolean, default: false)
belongs_to(:internal_rep, PortalApi.User)
belongs_to(:external_rep, PortalApi.User)
belongs_to(:company, PortalApi.Company)
belongs_to(:proposed_company, PortalApi.Company)
belongs_to(:lead_source, PortalApi.LeadSource)
belongs_to(:zipcode, PortalApi.Zipcode, on_replace: :nilify)
belongs_to(:quote_request, PortalApi.QuoteRequest)
has_many(:attachments, PortalApi.Attachment)
has_many(:activity_logs, PortalApi.ActivityLog)
has_many(:notes, PortalApi.Note)
timestamps()
end
Migration of specifications table:
def change do
alter table(:leads) do
add :specifications, :string
end
end
This update seem to update everything normally except that specification. I've tried checking everything from model, to migrations and controllers, but it just doesn't seem to store that column. I can assure you that Postgres table is fine and all required column exists.
What could be the issue? How can I solve this?
Thank you!