Hi,
I’m still stuck with a fundamental problem understanding how this hangs
together. Given two tables with a HABTM relationship through a
join_table as follows;
Model job:
class Job < ActiveRecord::Base
belongs_to :JobTypes
has_many :People
has_and_belongs_to_many :addresses, :join_table => “Jobs_Addresses”
has_many :Reminders
has_many :JobPhases
has_many :Discussions
has_many :actions
has_one :jobtype
has_many :documents
has_one :organisation
has_many :reminders
has_many :discussions
validates_associated :address
end
Model address:
class Address < ActiveRecord::Base
has_and_belongs_to_many :jobs, :join_table => “Jobs_Addresses”
has_one :Address_type
has_one :organisation
end
Model job_address
class JobAddress < ActiveRecord::Base
has_and_belongs_to_many :jobs
has_and_belongs_to_many :addresses
end
OK, heres my problem =>
In console I get to a job.
I can read its data, methods and attributes and I can return the address
data as follows;
@job.addresses
=> [#<Address:0x37dd170 @attributes={“Organisation_ID”=>nil,
“Address_2”=>nil, “Job_ID”=>“4”, “Country”=>“Australia”, “id”=>“2”,
“Suburb”=>“Mitcham”, “OrgType_ID”=>nil, “State”=>“Vic”,
“Address_1”=>“456, second st”, “Address_ID”=>“2”}>]
What I can’t figure is how to get at that attribute data to put into a
simple job list mixing the address in with the other job attributes!
Can somebody please explain before I go nuts!!
Kind Regards,
Eric.