[Rails-core] Allow to use Proc on :order option of associations

2012-05-03 Thread Gabriel Sobrinho
Take a look (not my production code but reproduces the desired behavior): ``` ruby class Post < ActiveRecord::Base attr_accessible :published_at, :name has_and_belongs_to_many :categories, :order => lambda { [Category.arel_table[:published_at].desc, Category.arel_table[:name]] } end ``` ```

Re: [Rails-core] Allow to use Proc on :order option of associations

2012-05-04 Thread Jon Leighton
There has been discussion about putting a new syntax into Rails 4 that more closely resembles scopes. Example: has_many :comments, -> { where(deleted: false).order(:created_at) } This would solve the problem of eager evaluation because it's contained in a lambda. I'll be looking into this wh

Re: [Rails-core] Allow to use Proc on :order option of associations

2012-05-04 Thread Gabriel Sobrinho
Thanks John! On Friday, May 4, 2012 7:48:34 AM UTC-3, Jon Leighton wrote: > > There has been discussion about putting a new syntax into Rails 4 that > more closely resembles scopes. Example: > > has_many :comments, -> { where(deleted: false).order(:created_at) } > > This would solve the problem

Re: [Rails-core] Allow to use Proc on :order option of associations

2012-05-04 Thread Rodrigo Rosenfeld Rosas
Em 04-05-2012 07:48, Jon Leighton escreveu: There has been discussion about putting a new syntax into Rails 4 that more closely resembles scopes. Example: has_many :comments, -> { where(deleted: false).order(:created_at) } For this particular case, I don't understand. What would be the advan

Re: [Rails-core] Allow to use Proc on :order option of associations

2012-05-04 Thread Gabriel Sobrinho
Yep, cross-reference. Both file needs to require the other to load :) Category definition needs Post defined Post definition needs Category defined We simply can't load these files in this way. On May 4, 2012, at 10:54 AM, Rodrigo Rosenfeld Rosas wrote: > Em 04-05-2012 07:48, Jon Leighton es

Re: [Rails-core] Allow to use Proc on :order option of associations

2012-05-04 Thread Rodrigo Rosenfeld Rosas
Ah, I see, thanks. Em 04-05-2012 11:14, Gabriel Sobrinho escreveu: Yep, cross-reference. Both file needs to require the other to load :) Category definition needs Post defined Post definition needs Category defined We simply can't load these files in this way. -- You received this message