meyercm / base_model Goto Github PK
View Code? Open in Web Editor NEWActiveRecord for Ecto
ActiveRecord for Ecto
The docs are sort of published to hexdocs: https://hexdocs.pm/base_model/
but it's empty!
I don't quite understand why… given that there's @docs
everywhere…
Hi @meyercm, thank you so much for making this lib. It's been a great help for me. There is a tiny issue though, when I define a create_changeset
in my schema, there is this compiling error said:
got "@impl BaseModel" for function create_changeset/1 but no behaviour was declared
.
The code of the schema looked like this:
defmodule AnnualPlan do
use Ecto.Schema
use BaseModel, repo: MyApp.Repo
import Ecto.Changeset
@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema "annual_plans" do
field(:body, :string)
field(:year, :string)
belongs_to(:user, MyApp.Accounts.User, type: :integer)
timestamps()
end
@impl BaseModel
def create_changeset(params) do
%__MODULE__{}
|> cast(params, [:year, :body, :user_id])
|> validate_required([:year, :body, :user_id])
end
end
Although the create_changeset
function still works, it would be great if there is no compile warning. Was I missing something?
Hi @meyercm , sorry for coming to complain again. Do you have any plans for generating a last
method(order_by: [desc: :inserted_at]
) for model, just like ActiveRecord#last
. I personally find it very useful.
Another feature I found useful is generating a bunch of methods that returns a Ecto.Query
. These methods could be bundled up in a generated Module, like Model.Query.query_method
.
For example.
User.Query.where(username: "chris")
would return a Query similar to from(User, where: [username: "chris"])
. This would simplify lots of boilerplate code when composing query or when using preload
.
Sorry for my poor English, I hope I've made myself clear.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.