[Rails] Finding by association

Jason Fox
2006-01-12T03:16:58Z

I have two objects that are associated in the following way:

  class Class1 < ApplicationController
    has_and_belongs_to_many :class2s
    has_and_belongs_to_many :otherClasses
  end

  class Class2 < ApplicationController
    has_and_belongs_to_many :class1s
    has_and_bleongs_to_many :otherClasses
  end

Now, when I run the following query,

  @objects = Class1.find(:all, :conditions => ["class2s.id = ?",
params[:id]], :include => :class2s)

I expect to get a collection of Class1 objects wihere each Class1 object
would have a fully loaded collection of Class2 objects (since I asked to
:include => :class2s).  However, instead, I get a collection of Class1
objects that only have a single Class2 object in their class2s
collection (the Class2 object with the id that I specified in the
conditions clause).

I''m thinking this might have something to do with the habtm bug that is
floating around, but am not sure.  Am I doing this right?  Any ideas?

- Jason

--
Posted via http://www.ruby-forum.com/.