To_xml and 3 levels of association?

Hi,

I successfully generated an XML file based on two table levels:


class Level1 < ActiveRecord::Base
has_many :level2s
end

class Level2 < ActiveRecord::Base
belongs_to :level1
end

l = Level1.find(1)
puts l.to_xml(:include => :level2s)

What about 3 levels? I tried using “has_many :through” but hierarchy
between the second and third levels is lost.


class Level1 < ActiveRecord::Base
has_many :level2s
has_many :level3s, :through => :level2s
end

class Level2 < ActiveRecord::Base
belongs_to :level1
has_many :level3s
end

class Level3 < ActiveRecord::Base
belongs_to :level2
End

l = Level1.find(1)
puts l.to_xml(:include => [:level2s, :level3s])

Thanks