> > Can I get an ActiveRecord.find to do this query?:   *Get all Articles
> > which have only been published in less than X Magazines.*

actually i think (and i'd not be very surprised if i was wrong with
this one) you can't do that in a simple call. however what you can do
is simulate it like this (in your Article model):

  def self.all_with_less_publications_than(limit)
    result_set = []
    Articles.all.each do |article|
      if article.magazines.count < limit
        result_set << article
      end
    end
    return result_set
  end

now you'll be able to call:

  Article.all_with_less_publications_than(5)

basically it does the same as your SQL statement. running through all
articles and counting the related magazines. this is obviously not the
shortest way to write such a method, but for the sake of readability
it's imho best to write it like that.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to