Using RoR 2.2.2 with MySql Server version: 5.0.75-0ubuntu10.5 on Ubuntu.

I have three tables/models and I want to do a find on Reservations ordering the results by the names in Sitetype.  Sql for tables and the models look like the following:

[sql]                                                                                     [models]
CREATE TABLE `reservations` (                        class Reservation < ActiveRecord::Base
  `id` int(11) NOT NULL AUTO_INCREMENT,                belongs_to :space
  `space_id` int(11) NOT NULL default '0',           end
  ...
  PRIMARY KEY  (`id`)
);

CREATE TABLE `spaces` (                              class Space < ActiveRecord::Base
   `id` int(11) NOT NULL auto_increment,               belongs_to :sitetype
  `name` varchar(24) NOT NULL default '',              has_many :reservations
  `sitetype_id` mediumint(9) NOT NULL default '0',   end
  ...
  PRIMARY KEY  (`id`)
);

CREATE TABLE `sitetypes` (                           class Sitetype < ActiveRecord::Base
  `id` int(11) NOT NULL auto_increment,                has_many :spaces
  `name` varchar(12) NOT NULL default '',              has_many :reservations, :through => :spaces
  PRIMARY KEY  (`id`)                                end
); 


I have tried a number of things using includes of spaces and sitetypes but I have never been able to get the desired result.  I can easily get it ordered by space.name using 
r=Reservation.find(:all, :include => "space", :order => "spaces.name asc")
Whenever I try to include sitetype as in
r=Reservation.find(:all, :include => [:space, :sitetype], :order => "sitetypes.name asc")
I get a complaint "Association named 'sitetype' was not found"

Could someone who understands this better than I recommend an approach to do what is needed here?

Norm

--
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