This project is archived and is in readonly mode.
ActiveSupport OptionMerger to merge lambdas
Reported by Paweł Kondzior | July 30th, 2008 @ 12:59 PM | in 2.x
Right now it is imposible to use with_options when we have named_scope with lambdas example:
with_options(:include => [:foo]) do |options|
options.named_scope :order_by, lamdba { |order| { :order => order }
end
This patch will allow ActiveSupport.OptionMerger to deep_merge lambda expressions.
Comments and changes to this ticket
-
Paweł Kondzior July 30th, 2008 @ 01:26 PM
- no changes were found...
-
Paweł Kondzior August 1st, 2008 @ 11:17 AM
- Assigned user set to josh
-
Paweł Kondzior August 4th, 2008 @ 08:53 AM
- Assigned user cleared.
-
Paweł Kondzior August 4th, 2008 @ 09:48 AM
maybe first example doesn't show what benefits we have from this patch.
class Article belongs_to :author has_many :comments with_options(:include => [:author, :comments], :order => 'created_at DESC') do |base| base.named_scope :order_by, lambda { |order| { :order => order } } base.nameD_scope :created_by, lambda { |author| { :conditions => ['created_by = ?', author.id } } end end
It is much Dry to use with_otpions and just type Article.order_by("authors.name DESC") than doin Article.base.order_by("authors.name DESC")
-
Jacek Becela November 15th, 2008 @ 12:52 PM
After I started using named_scopes, all my models contain a few or often more than a dozen named_scopes with lambdas and I could really use such a feature.
This is better than chaining some common named_scope with every other scope, like say: Article.with_author_and_comments.order_by(something).
On the other hand, there is another problem that this patch would not solve, and I'd love it had:
Say you have a deleted_at column which is a common pattern for having "undo" in your app, etc.
I'd like to have a DEFAULT named_scope so Article.all and Article.order_by(something) would always add SQL fragment "deleted_at is null". A default named_scope.
Implementation would of course go into named_scope and not into OptionMerger.
-
Paweł Kondzior November 15th, 2008 @ 03:41 PM
Jacek: look at this ticket: http://dev.rubyonrails.org/ticke... and http://github.com/rubaidh/defaul...
I think too that it would be very cool to have default_scope inside AR.
-
DHH November 15th, 2008 @ 03:49 PM
- State changed from new to committed
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>