Re: [Rails] Finding non-empty has_many associations with a named_scope

2009-12-13 Thread maryam kamali
ithank iam very rech no help by On Sun, Dec 13, 2009 at 2:10 AM, Ryan Waldron r...@erebor.com wrote: If I have these classes: class Customer ActiveRecord::Base has_many :jobs ... end class Job ActiveRecord::Base belongs_to :customer ... end can I construct a named scope that

[Rails] Finding non-empty has_many associations with a named_scope

2009-12-12 Thread Ryan Waldron
If I have these classes: class Customer ActiveRecord::Base has_many :jobs ... end class Job ActiveRecord::Base belongs_to :customer ... end can I construct a named scope that returns the equivalent collection (but hopefully more efficient) to this: customers_with_jobs =

Re: [Rails] Finding non-empty has_many associations with a named_scope

2009-12-12 Thread Leonardo Mateo
On Sat, Dec 12, 2009 at 7:40 PM, Ryan Waldron r...@erebor.com wrote: If I have these classes: class Customer ActiveRecord::Base   has_many :jobs ... end class Job ActiveRecord::Base   belongs_to :customer ... end can I construct a named scope that returns the equivalent collection

Re: [Rails] Finding non-empty has_many associations with a named_scope

2009-12-12 Thread Ryan Waldron
Well, it kind of does the wrong join: c = Customer.all.reject{|j| j.jobs.empty?} [...] c.size = 2125 c = Customer.with_jobs Customer Load (165.5ms) SELECT SQL_NO_CACHE `customers`.* FROM `customers` INNER JOIN `jobs` ON jobs.customer_id = customers.id WHERE (jobs.customer_id IS NOT NULL)