Hello everyone.
I have two Classes, linked by a HABTM relationship.
class Building < ActiveRecord::Base
set_table_name ''gc_edifici_attivita''
has_and_belongs_to_many :jobs, :join_table =>
''gc_edificio_avvio_commessa'', :foreign_key =>
''edificio_attivita_gc_id'', :class_name =>
''Job''
end
class Job < ActiveRecord::Base
set_table_name ''gc_avvio_commessa''
has_and_belongs_to_many :buildings, :join_table
=>''gc_edificio_avvio_commessa'', :foreign_key =>
''commessa_id'', :class_name => ''Building'',
:association_foreign_key =>
''edificio_attivita_gc_id''
end
Ok, table names are in Italian.. that''s because I had to use a legacy
database and could not change the tables'' names.
Now, for each Job, I have to list all the Buildings related to it. So
it goes like this:
@jobs = Job.all
@jobs.each do |job|
job.buildings [... do something with the buildings...]
end
Everything goes well so far. But sometimes, I have to list only the
Jobs happening on a given Building, yielding:
@jobs = Building.find(params[:building]).jobs
@jobs.each do |job|
job.buildings [... do something with the buildings...]
end
This won''t work anymore; Rails keeps telling me there''s no
such method
as ''buildings'' for class ''Job''.
it''s almost as if collecting the Jobs
from a Building through HABTM, Rails cannot ''see'' what methods
are in
class Job.
Any ideas about this? Is there a bug in Rails, or is this supposed to
happen?
Thanks in advance to anyone who might help me.
Regards,
Rey9999
--~--~---------~--~----~------------~-------~--~----~
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---