You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
Model.last has been on my to-do list. However, since not all models will have :inserted_at, my plan had been to use order_by: [desc: <pk>], which works for most choices of primary key type, but breaks down for guids. I'm tempted to provide the signature last(by_column \\ :__schema_primary_key__), however, that precludes providing a count, the way it works in ActiveRecord (you wouldn't be able to write User.last(3) like in their documentation ). ActiveRecord solves the problem with their default_scope, which is a feature I never used in Ruby, and so didn't make it in the original BaseModel. I could refactor to include it now, probably as a callback, similar to create_changeset. I'm open to ideas for making last syntax both convenient and consistent with the rest of BaseModel.
I'll have to think some on your Model.Query notion. In my production code, as soon as I need something that BaseModel doesn't provide, I write a method in the model that just uses Ecto directly. However, I could see this being very useful while debugging on the console. What I don't want to do is re-write Ecto.Query; the goal of BaseModel is just to make using Ecto very easy for the most common calls.
It would help if you had some complete examples of how you would like to use it. I know that isn't easy, since the feature doesn't exist yet, but I'm having a hard time weighing the value in the abstract.
Also, your English is great- if you aren't a native speaker, you should be proud.
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 likeActiveRecord#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, likeModel.Query.query_method
.For example.
User.Query.where(username: "chris")
would return a Query similar tofrom(User, where: [username: "chris"])
. This would simplify lots of boilerplate code when composing query or when usingpreload
.Sorry for my poor English, I hope I've made myself clear.
The text was updated successfully, but these errors were encountered: