|
|
|
|
|
by out_of_protocol
34 days ago
|
|
> ActiveRecord is more pleasant to work with than the ORM of Phoenix IMHO, but not everyone shares the same feeling. Well, depends on what you do. Ecto is closely follows SQL logic and allows to translate weird sql queries into code directly. All queries are explicit, e.g. you either do preload(...) or can't access nested records at all, no chance of N+1 by design. Changesets are also different and are just functions you can define as needed. defmodule MyApp.User do
...
def changeset(user, attrs) do
user
|> cast(attrs, [:email])
|> validate_required([:email])
# This matches the error from the DB uniq index to the :email field
|> unique_constraint(:email)
end
|
|
Your example is a common anti pattern from PHP orms 15 years ago.