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
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 =
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
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)
4 matches
Mail list logo