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 when I get around to it.
On 03/05/12 19:28, Gabriel Sobrinho wrote:
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
```
``` ruby
class Category < ActiveRecord::Base
attr_accessible :published_at, :name
has_and_belongs_to_many :posts, :order => lambda {
[Post.arel_table[:published_at].desc, Post.arel_table[:name]] }
end
```
``` ruby
Category.first.posts
# => TypeError: Cannot visit Proc
```
``` ruby
Post.first.categories
# => TypeError: Cannot visit Proc
```
The problem happens when we have a cross reference between two models
and need to use arel due to difference on quote of columns.
Sounds reasonable?
Reference: https://github.com/rails/rails/issues/6146
--
You received this message because you are subscribed to the Google
Groups "Ruby on Rails: Core" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/rubyonrails-core/-/I5NDxR9PCvgJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en.
--
http://jonathanleighton.com/
--
You received this message because you are subscribed to the Google Groups "Ruby on
Rails: Core" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en.