<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: More Named Scope Awesomeness</title>
	<atom:link href="http://www.pathf.com/blogs/2008/06/more-named-scope-awesomeness/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pathf.com/blogs/2008/06/more-named-scope-awesomeness/</link>
	<description>Running commentary about agile development, user experience design and Ajax.</description>
	<pubDate>Fri, 05 Dec 2008 08:21:26 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: Pathfinder Development &#187; I&#8217;m Cranky Because I&#8217;m Not Getting Enough REST</title>
		<link>http://www.pathf.com/blogs/2008/06/more-named-scope-awesomeness/#comment-3110</link>
		<dc:creator>Pathfinder Development &#187; I&#8217;m Cranky Because I&#8217;m Not Getting Enough REST</dc:creator>
		<pubDate>Fri, 22 Aug 2008 21:02:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=995#comment-3110</guid>
		<description>[...] that triggers an overlay, you can sort the columns. The advanced search is the flexible one I mention here, so it's got several Ajax calls associated with it as [...]</description>
		<content:encoded><![CDATA[<p>[...] that triggers an overlay, you can sort the columns. The advanced search is the flexible one I mention here, so it&#8217;s got several Ajax calls associated with it as [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fredrik W</title>
		<link>http://www.pathf.com/blogs/2008/06/more-named-scope-awesomeness/#comment-2443</link>
		<dc:creator>Fredrik W</dc:creator>
		<pubDate>Wed, 16 Jul 2008 08:43:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=995#comment-2443</guid>
		<description>Here's some code that I came up with a week ago. 

http://pastie.org/231954

Is basically takes an array of different scopes you wish to apply and injects them into the the model. I haven't thought of AND/OR joins yet though.</description>
		<content:encoded><![CDATA[<p>Here&#8217;s some code that I came up with a week ago. </p>
<p><a href="http://pastie.org/231954" rel="nofollow">http://pastie.org/231954</a></p>
<p>Is basically takes an array of different scopes you wish to apply and injects them into the the model. I haven&#8217;t thought of AND/OR joins yet though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jtoy</title>
		<link>http://www.pathf.com/blogs/2008/06/more-named-scope-awesomeness/#comment-2284</link>
		<dc:creator>jtoy</dc:creator>
		<pubDate>Fri, 04 Jul 2008 11:59:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=995#comment-2284</guid>
		<description>There seems to be a bug in the code,  if I do a :
Model.some_scoped_proxy.search_by(@searches)
search_by will ignore the previous named_scopes.
but if I do
Model.search_by(@searches).some_scoped_proxy
that will generate the proper sql.

Also I had a seperate question, I tried making my own simple example based off your code.  I want a order named_proxy on all AR models, but my code doesn't work because when it calls column_names the lambda thinks its calling it on ActiveRecord::Base instead of the subclassed model. Why does this not work?

class ActiveRecord::Base
  named_scope :order, lambda {&#124;column&#124;
    if column_names.include? column
      {:order =&#62; column}
    end
  }

end

Also one other thing I noticed about scopes is that they dont override previous scopes, so for example Car.order('a').order('b')
I would think that following the "ruby way" of least suprise, the order would on b, but its actually on a</description>
		<content:encoded><![CDATA[<p>There seems to be a bug in the code,  if I do a :<br />
Model.some_scoped_proxy.search_by(@searches)<br />
search_by will ignore the previous named_scopes.<br />
but if I do<br />
Model.search_by(@searches).some_scoped_proxy<br />
that will generate the proper sql.</p>
<p>Also I had a seperate question, I tried making my own simple example based off your code.  I want a order named_proxy on all AR models, but my code doesn&#8217;t work because when it calls column_names the lambda thinks its calling it on ActiveRecord::Base instead of the subclassed model. Why does this not work?</p>
<p>class ActiveRecord::Base<br />
  named_scope :order, lambda {|column|<br />
    if column_names.include? column<br />
      {:order =&gt; column}<br />
    end<br />
  }</p>
<p>end</p>
<p>Also one other thing I noticed about scopes is that they dont override previous scopes, so for example Car.order(&#8217;a').order(&#8217;b')<br />
I would think that following the &#8220;ruby way&#8221; of least suprise, the order would on b, but its actually on a</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Noel Rappin</title>
		<link>http://www.pathf.com/blogs/2008/06/more-named-scope-awesomeness/#comment-2276</link>
		<dc:creator>Noel Rappin</dc:creator>
		<pubDate>Thu, 03 Jul 2008 22:26:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=995#comment-2276</guid>
		<description>James and Ben -- in the actual version of this, the user is limited to a specific subset (I think delete_all is excluded because it'll cause an error when composed with other scopes), plus there are some additional scopes tacked on to all the searches to limit users to objects that they have access to see. Although I probably could do a tighter job of limiting the searches.

Tammer -- thanks for the kind words, we use a lot of thoughtbot tools on a daily basis here..</description>
		<content:encoded><![CDATA[<p>James and Ben &#8212; in the actual version of this, the user is limited to a specific subset (I think delete_all is excluded because it&#8217;ll cause an error when composed with other scopes), plus there are some additional scopes tacked on to all the searches to limit users to objects that they have access to see. Although I probably could do a tighter job of limiting the searches.</p>
<p>Tammer &#8212; thanks for the kind words, we use a lot of thoughtbot tools on a daily basis here..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nick Kallen</title>
		<link>http://www.pathf.com/blogs/2008/06/more-named-scope-awesomeness/#comment-2247</link>
		<dc:creator>Nick Kallen</dc:creator>
		<pubDate>Tue, 01 Jul 2008 05:42:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=995#comment-2247</guid>
		<description>Love the articles. Inject is great:

      all_criteria.inject(scoped({})) do &#124;scope, criterion&#124;
        scope.scoped(search_by_criteria(*criterion).proxy_options)
      end</description>
		<content:encoded><![CDATA[<p>Love the articles. Inject is great:</p>
<p>      all_criteria.inject(scoped({})) do |scope, criterion|<br />
        scope.scoped(search_by_criteria(*criterion).proxy_options)<br />
      end</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben Nolan</title>
		<link>http://www.pathf.com/blogs/2008/06/more-named-scope-awesomeness/#comment-2240</link>
		<dc:creator>Ben Nolan</dc:creator>
		<pubDate>Sun, 29 Jun 2008 00:48:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=995#comment-2240</guid>
		<description>I'm guessing you check that the operators are from a valid subset - so that people can't ask for the delete_all operator?</description>
		<content:encoded><![CDATA[<p>I&#8217;m guessing you check that the operators are from a valid subset - so that people can&#8217;t ask for the delete_all operator?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David</title>
		<link>http://www.pathf.com/blogs/2008/06/more-named-scope-awesomeness/#comment-2234</link>
		<dc:creator>David</dc:creator>
		<pubDate>Sat, 28 Jun 2008 13:26:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=995#comment-2234</guid>
		<description>Nice, I'm just learning named_scope and used it in a project this week. I figured there was a way to generate anonymous scopes on the fly to simplify all my crazy conditional logic. This example really helps alot. cheers mate.</description>
		<content:encoded><![CDATA[<p>Nice, I&#8217;m just learning named_scope and used it in a project this week. I figured there was a way to generate anonymous scopes on the fly to simplify all my crazy conditional logic. This example really helps alot. cheers mate.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rafi</title>
		<link>http://www.pathf.com/blogs/2008/06/more-named-scope-awesomeness/#comment-2230</link>
		<dc:creator>Rafi</dc:creator>
		<pubDate>Fri, 27 Jun 2008 21:17:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=995#comment-2230</guid>
		<description>Useful stuff. It's good to see that the chained scopes will get rolled up into a single SQL statement (avoiding the normal AR foo.bar.baz problem, where missing includes cause lots of trips to the DB).

The first example did trip a buzzer for me, tho. IIRC MySQL, LIKEs need to start with a non-wildcard ('foo%') to take advantage of the indexes, which are usually btrees built from the left side of string. (http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html) Not sure if FULLTEXT indexes help this, haven't gotten to dig in.

So if this makes it easy to do searches with '%foo' and '%foo%', there's a noticeable DB impact.</description>
		<content:encoded><![CDATA[<p>Useful stuff. It&#8217;s good to see that the chained scopes will get rolled up into a single SQL statement (avoiding the normal AR foo.bar.baz problem, where missing includes cause lots of trips to the DB).</p>
<p>The first example did trip a buzzer for me, tho. IIRC MySQL, LIKEs need to start with a non-wildcard (&#8217;foo%&#8217;) to take advantage of the indexes, which are usually btrees built from the left side of string. (http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html) Not sure if FULLTEXT indexes help this, haven&#8217;t gotten to dig in.</p>
<p>So if this makes it easy to do searches with &#8216;%foo&#8217; and &#8216;%foo%&#8217;, there&#8217;s a noticeable DB impact.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tammer Saleh</title>
		<link>http://www.pathf.com/blogs/2008/06/more-named-scope-awesomeness/#comment-2229</link>
		<dc:creator>Tammer Saleh</dc:creator>
		<pubDate>Fri, 27 Jun 2008 21:00:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=995#comment-2229</guid>
		<description>The power of named_scopes and of the scoped method is just incredible, and this technique in particular looks really interesting.  I figured I should mention that we recently got squirrel working with scoped, which makes complex finders like this both easy to read and build.

    http://giantrobots.thoughtbot.com/2008/6/25/named-scopes-with-squirrel

Thanks for the great post, and you've got a new subscriber.</description>
		<content:encoded><![CDATA[<p>The power of named_scopes and of the scoped method is just incredible, and this technique in particular looks really interesting.  I figured I should mention that we recently got squirrel working with scoped, which makes complex finders like this both easy to read and build.</p>
<p>    <a href="http://giantrobots.thoughtbot.com/2008/6/25/named-scopes-with-squirrel" rel="nofollow">http://giantrobots.thoughtbot.com/2008/6/25/named-scopes-with-squirrel</a></p>
<p>Thanks for the great post, and you&#8217;ve got a new subscriber.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Golick</title>
		<link>http://www.pathf.com/blogs/2008/06/more-named-scope-awesomeness/#comment-2228</link>
		<dc:creator>James Golick</dc:creator>
		<pubDate>Fri, 27 Jun 2008 20:10:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=995#comment-2228</guid>
		<description>Cool. My has_browser plugin does a very similar thing to search_by_criteria, except that it allows you to choose which scopes should be exposed (a little bit like attr_accessible), for security reasons.

http://jamesgolick.com/2008/5/19/introducing-has_browser-parameterized-browse-interfaces-for-your-ar-models</description>
		<content:encoded><![CDATA[<p>Cool. My has_browser plugin does a very similar thing to search_by_criteria, except that it allows you to choose which scopes should be exposed (a little bit like attr_accessible), for security reasons.</p>
<p><a href="http://jamesgolick.com/2008/5/19/introducing-has_browser-parameterized-browse-interfaces-for-your-ar-models" rel="nofollow">http://jamesgolick.com/2008/5/19/introducing-has_browser-parameterized-browse-interfaces-for-your-ar-models</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>
