Skip to content

Instantly share code, notes, and snippets.

@jamesbebbington
Created March 16, 2011 18:27
Show Gist options
  • Save jamesbebbington/873017 to your computer and use it in GitHub Desktop.
Save jamesbebbington/873017 to your computer and use it in GitHub Desktop.
class Project < ActiveRecord::Base
named_scope :foo, :conditions => ['projects.id IN(?)', [1,2,3]]
named_scope :bar, :conditions => ['projects.id IN(?)', [2,3,4]]
end
$ ./script/console
Loading development environment (Rails 2.3.9)
ree-1.8.7-2010.02 :001 > Project.foo.bar
Project Load (0.5ms) SELECT * FROM `projects` WHERE ((projects.id IN(2,3,4)) AND (projects.id IN(1,2,3))) ORDER BY projects.name
[
[0] Far Away {
:id => 3,
:brand_id => 3,
:state => "unpublished",
:locale => :"en-GB",
:name => "Far Away",
:description => "This project isn't going to be published until 2014.",
:notifiable => true,
:digestable => true,
:published_on => Mon, 01 Dec 2014,
:closed_on => Wed, 31 Dec 2014,
:created_at => Fri, 27 Nov 2009 12:19:25 UTC +00:00,
:updated_at => Wed, 09 Feb 2011 12:22:57 UTC +00:00
},
[1] Liveminds QA Iteration 1 {
:id => 2,
:brand_id => 3,
:state => "closed",
:locale => :"en-GB",
:name => "Liveminds QA Iteration 1",
:description => "An internal project used as a test for the Liveminds application.",
:notifiable => true,
:digestable => true,
:published_on => Mon, 02 Nov 2009,
:closed_on => Wed, 21 Jul 2010,
:created_at => Thu, 12 Nov 2009 09:54:04 UTC +00:00,
:updated_at => Tue, 15 Mar 2011 10:16:23 UTC +00:00
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment