Wednesday, 15 August 2012

Rails 4: has_many through association not working - tricky association key handling -



Rails 4: has_many through association not working - tricky association key handling -

updated question:

note: org table in remote db (likely source of problem)

a has_may through association not working , cannot figure out why. hoping can identify problem.

company model (companies table in local db)

has_many :locations, class_name: "org", primary_key: :name, foreign_key: :c_name has_many :reviews, through: :locations

org model (orgs table in remote db, using establish_connection reach it)

belongs_to :company, primary_key: :name, foreign_key: :c_name has_many :reviews, primary_key: :key, foreign_key: :location_id

review model (reviews table in local db)

i do:

company.reviews.count

but fails trying reach orgs table on local db and, of course, can't find it. company.locations.count works fine expected tho.

try changing org model's first belongs_to line to:

belongs_to :c_name, class_name: 'company'

ruby-on-rails has-many-through

No comments:

Post a Comment