[Rails-core] Re: Allow to use rails style on queries with specific order

2017-10-19 Thread Martin Hong
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,

[Rails-core] Add option to sort by an attribute before validation of has_many members with indexed errors

2017-10-19 Thread André Hester
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

Re: [Rails-core] Allow to use rails style on queries with specific order

2017-10-19 Thread Kevin Deisz
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

[Rails-core] Allow to use rails style on queries with specific order

2017-10-19 Thread Pablo Margreff
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

Re: [Rails-core] Change where module file goes for namespaced AR models

2017-10-19 Thread Matt Jones
> 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: > >