Muhammad-Mullah

Muhammad-Mullah

am a bit surprised. in my model i have specified fields that are required in the validate_required function. ironically when i try to submit a form with nil values it submits with no validation errors. This happens only in two models. What could be the reason? Thank you

Showing Posts 1 to 10

kokolegorille

kokolegorille

Please show your schemas. ( Remember models are gone in favor of schema since Phoenix 1.3.x :slight_smile: )

In particular, the changeset section, It would be easier to tell…

Muhammad-Mullah

Muhammad-Mullah OP

schema "houses" do
    field :house_type,          :string
    field :house_number,        :string
    field :house_location,      :string



    #Associations
    belongs_to :user, Zito.User, foreign_key: :user_id

    timestamps()
  end


  def changeset(struct, params \\ %{}) do
    struct
    |> cast(params, [:house_type, :house_number, :house_location])
    |> validate_required([:house_type, :house_number, :house_location])
  end
Muhammad-Mullah

Muhammad-Mullah OP

by the way am using Phoenix 1.2

kokolegorille

kokolegorille

Assuming your app name is Zito and your schema is House…

Try this in the console…

iex> c = Zito.House.changeset %Zito.House{}, %{}

Check that the changeset is invalid.

You should show the code You tried… Like this it’s hard to tell.

BTW Your syntax seems correct so far.

Muhammad-Mullah

Muhammad-Mullah OP

this is what i get

Zito.House.changeset(%Zito.House{__meta__: #Ecto.Schema.Metadata<:built, "houses">,  house_location: nil, house_number: nil, house_type: nil, id: nil, inserted_at: nil, updated_at: nil, user: #Ecto.Association.NotLoaded<association :user is not loaded>, user_id: nil}, %{})
Muhammad-Mullah

Muhammad-Mullah OP

it was just working. never changed, at first i thought maybe i should restart my server. I also did update all my dependancy thought maybe could be an issue with dependancies

kokolegorille

kokolegorille

If it was working, then broke when You updated… If You kept the old version, I would say restart from it, then update dependencies one by one, to see which break your system.

Sorry, but those errors are hard to debug without more context.

Muhammad-Mullah

Muhammad-Mullah OP

running this in the in the console house = House.changeset(%House{}, %{}) gives me this results

#Ecto.Changeset<
  action: nil,
  changes: %{},
  errors: [
    house_type: {"can't be blank", [validation: :required]},
    house_number: {"can't be blank", [validation: :required]},
    house_location: {"can't be blank", [validation: :required]},
  ],
  data: #Zito.House<>,
  valid?: false
>
kokolegorille

kokolegorille

The point was to test if the changeset is not valid, as You expect it to be. And it is, so your problem might be in the create action of the house controller.

Muhammad-Mullah

Muhammad-Mullah OP

okay, let me check my create function

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
jaybe78
Hello, I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter). The diffic...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews