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
```
```
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
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
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
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
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