15 Dec
duccio

duccio il 15 December 2009 parla di Rails Snippet

Ignorare il default_scope

Può essere utile mettere un default_scope per filtrare a monte determinati contenuti, il problema è che se usate questo tipo di scope, verrà applicato sempre anche quando magari non serve.

Per evitare il problema o usate i named_scope, oppure usate il with_exclusive_scope.

    1 default_scope :conditions => ["field = ?", valore], :order => 'published_at DESC'

Se usate il with_exclusive_scope ingnorerete il default_scope:

    1 Content.send(:with_exclusive_scope) {
    2   Content.find(:all)
    3 }

Scrivi un commento