Forum: Ruby on Rails Through method problems with custom foreign_keys

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Chris (Guest)
on 2006-03-15 13:25
A person has a many company_branches and
A company_branch has many people.
This join is represented using a "contacts" table.
I am using a legacy schema so i am forced into using non-standard rails
primary keys. I am using the new through relationship in rails 1.1.

b=p.company_branches # gives this error:

ActiveRecord::StatementInvalid: OCIError: ORA-00904:
ID": invalid identifier: SELECT company_branches.* FROM contacts,
es WHERE (company_branches.branch_id = contacts.company_branch_id AND
erson_person_id = 1)

Notice that "contacts.company_branch_id" does not exist, it should be

Here are the models:

class Person < ActiveRecord::Base
  set_primary_key "person_id"

  has_many  :contacts,

  has_many  :company_branches,

class CompanyBranch < ActiveRecord::Base

  set_primary_key "branch_id"

  belongs_to  :company,

  has_many  :contacts,

class Contact < ActiveRecord::Base
  set_primary_key "contact_id"

  belongs_to  :company_branch,

  belongs_to  :person,

Any idea what is wrong? Any help would be greately appreciated!
Lee M. (Guest)
on 2006-03-18 00:15
(Received via mailing list)
I believe I ran across the same problem when trying a self-referential
has_many :through relationship.  I've submitted a patch at that seems to fix it for me.
You may want to give it a shot.
This topic is locked and can not be replied to.