tduccuong

tduccuong

Function overriding causes warning

Hi, I have a “base” module with this

defmodule DbModel do
  @callback schema()  :: Map.t

  defmacro __using__(_opts) do
    quote do
      @behaviour DbModel

      ...boiler plates with actual implementation...

      def schema(),       do: %{}
      defoverridable schema: 0
    end
  end

  ...stuffs implemented for this base module...
end

Then I have a module

defmodule CustomerM do
  defstruct id:            nil,
                 ...other props...
  use ExConstructor

  @impl DbModel
  def schema(), do: %{
     ...specific schema validation and conversion...
  }

  use DbModel
end

It works well for my application, but one thing bugs me is this:

warning: this clause cannot match because a previous clause at line xx always matches
  lib/db/model/customer_m.ex:31

Yes, I know about Ecto etc, but I choose this way of handling db model for a reason.

My question is more general: What is the correct way to achieve this kind of function overriding?

Thanks a lot!

Marked As Solved

tduccuong

tduccuong

that is it, thanks!

Where Next?

Popular in Questions Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New

Other popular topics Top

JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54921 245
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 44532 311
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement