require 'rubygems';require 'active_record'; require 'mysql';
ActiveRecord::Base.establish_connection(:adapter =>
'mysql', :database => "idea", :username => "myname", :password =>
'mypswd')
class Employee < ActiveRecord::Base
belongs_to :department
end
class Department < ActiveRecord::Base
has_many :departments
- has_many :comments
+ has_many :customers
end
class Customer < ActiveRecord::Base
belongs_to :department
end
> > e = Employee.find(1)
> > #to find the number of customers associated with a particular employee
> > within a department
> > p e.department.customers.size
Sorry, those were typos. Customer is singular and there is no
comments database just a customers one. That is, comments should have
been customers. As noted, the program does work perfectly, except in
Rails and of course it couldn't possibly be a problem of ids because I
can get it to work in Rails as well but only if I use a two step
procedure. As noted, x = e.department and then x.customers.size
Therefore, it is not a problem of ids as it works in rails 2.3.5, it
just takes two steps but why two steps instead of one?
--
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.