I just meet the same problem like you
ORDER_PRIORITIES = [:removed, :new, :active, :corrupted]
def self.priorities_based_order
conditions = ORDER_PRIORITIES.each_with_index.map { |value, index| "WHEN
#{value} THEN #{index} ELSE 999" }.join("\n") # I want other statuses to be
sorted lastly, you
I would like to introduce an option *order_before_validation* for *has_many*
associations:
If you add new objects via an Rails API to an `has_many` association via
nested attributes and you would like to keep the order of the collection
sorted by an attribute the matching of the errors via `inde
Are you using MySQL? It has a field function that solves this
https://www.w3schools.com/sql/func_mysql_field.asp
You could probably do the same thing with substring index with other DBMSs.
On Thu, Oct 19, 2017 at 1:30 PM Pablo Margreff wrote:
> I have a situation which I need use a specific or
I have a situation which I need use a specific order for queries which the
attributes are an enum, something like this:
*.order("x.status = 5, x.status = 1, x.status = 6 ...")*, but it isn't the
best way for readability, and I haven't found anything about how to do it
on rails way.
Is a big
> On Oct 18, 2017, at 3:56 PM, Matt Wire wrote:
>
> Hello all!
>
> Because Rails apps get cluttered up rather quickly, I am proposing a change
> to this Rails generator method:
>
> https://github.com/rails/rails/blob/master/activerecord/lib/rails/generators/active_record/model/model_generator