nathaniel bibler

Random thoughts, links, and code by Nathaniel Bibler

Named Scopes with PostgreSQL

When using chained named scopes that modify the :select finder option, the PostgreSQL adapter appears to give SELECT query preference to the first scope defined:

named_scope :foo, {:select => "foo.*"}
named_scope :bar, {:select => "bar.*"}

Tester.bar.foo.all #=> SELECT bar.* FROM tester...
While it seems somewhat straightforward in this example, when chaining multiple scopes, it is somewhat counter-intuitive that the first takes precedence.