{"id":2422,"date":"2022-08-30T15:24:44","date_gmt":"2022-08-30T15:24:44","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/01\/12\/problem-about-scopes-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:24:44","modified_gmt":"2022-08-30T15:24:44","slug":"problem-about-scopes-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/problem-about-scopes-collection-of-common-programming-errors\/","title":{"rendered":"problem about scopes-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/2f2a9ed7d2ebb95975afef8de6ce20fc?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nPrince John Wesley<br \/>\nruby-on-rails-3 ruby-on-rails-3.1 scopes<br \/>\nI stumbled upon a wonderful article about scopes on Rails 3+ : http:\/\/edgerails.info\/articles\/what-s-new-in-edge-rails\/2010\/02\/23\/the-skinny-on-scopes-formerly-named-scope\/index.htmlYou can read there (in &#8216;Crazy Town&#8217; section) that it&#8217;s possible to merge scopes from different models like this :class User &lt; ActiveRecord::Basescope :published, lambda {joins(:posts).group(&#8220;users.id&#8221;) &amp; Post.published} endwhich works just as expected, and allows you to do :User.published.to_sql #=&gt; SELECT<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/5cc165c5b9f18bfb64faddb021c82172?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nBrendon Muir<br \/>\nruby-on-rails-2 scopes<br \/>\nI&#8217;m upgrading from Rails 2.3.5 to 2.3.17 and have come across a pretty obscure problem. I use the following extensions to inject a scope within an association accessor, and provider a custom builder:module XYZFilterExtensiondef in_context(context)if proxy_owner.context == :abc &amp;&amp; context != :adminscoped(:conditions =&gt; {:startup =&gt; false})elsescoped({})endendendmodule OtherExtensiondef build_with_component_instance(attributes = nil)attributes ||= {}attributes.reverse_merge!(:parent_<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/e731af79d198e0c2263695da245e0996?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\njklina<br \/>\nruby-on-rails ruby-on-rails-3 meta-search scopes<br \/>\nIn my Widget model I have the following:scope :accessible_to, lambda { |user|if user.has_role?(&#8216;admin&#8217;)self.allelseroles = user.rolesrole_ids = []roles.each { |r| role_ids &lt;&lt; r.id }self.joins(:widget_assignments).where(&#8216;widget_assignments.role_id&#8217; =&gt; role_ids)end }Ideally, I would like to use this scope as a filter for Ransack&#8217;s search results, so in my controller I have:def index@q = Widget.accessible_to(current_user).search(params[:q])@widgets = @q.result.order(&#8216;created_at DESC&#8217;) endD<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/6569e02e1e0e2085fd02063195a3dd07?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nStu<br \/>\nyii relation scopes default-scope<br \/>\nI can&#8217;t find too much documentation on applying a default scope to a model in yii, I was wondering if someone could explain or point me in the right direction.The quick version of my question:Is it possible to add a relation to a default scope, or to add a &#8216;with&#8217; criteria by default to every AR search on a model?The long version of my question:A quick summary of my app:I have two models, provider and item. Which have a m:1 relationship where a provider can have many item&#8217;s, but each item can onl<\/li>\n<\/ul>\n<p id=\"rop\"><small>Originally posted 2014-01-12 04:48:18. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>Prince John Wesley ruby-on-rails-3 ruby-on-rails-3.1 scopes I stumbled upon a wonderful article about scopes on Rails 3+ : http:\/\/edgerails.info\/articles\/what-s-new-in-edge-rails\/2010\/02\/23\/the-skinny-on-scopes-formerly-named-scope\/index.htmlYou can read there (in &#8216;Crazy Town&#8217; section) that it&#8217;s possible to merge scopes from different models like this :class User &lt; ActiveRecord::Basescope :published, lambda {joins(:posts).group(&#8220;users.id&#8221;) &amp; Post.published} endwhich works just as expected, and allows you to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2422","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2422","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2422"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2422\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2422"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2422"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2422"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}