This project is archived and is in readonly mode.
ActiveSupport OptionMerger to merge lambdas
-
hosiawak
+1
-
Paweł Kondzior
- Assigned user set to josh
-
Paweł Kondzior
- Assigned user cleared.
-
Paweł Kondzior
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 endIt 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
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
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
- State changed from new to committed
