Forum: Ruby on Rails Single Table Inheritance and HABTM Problem

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
0ff7e5d45c4da4a1719efd9c8caaa404?d=identicon&s=25 Roman Ilin (purplehaze)
on 2007-04-07 12:08
I have Models:

class User < ActiveRecord::Base
end

class Dozent < User
  has_and_belongs_to_many :subjects, :foreign_key=>'user_id' ,
:join_table => "subjects_users"
end

class Subject < ActiveRecord::Base
  has_and_belongs_to_many :dozents, :join_table => "subjects_users",
:foreign_key=>'subject_id'
end

Join Table is 'subjects_users':
subject_id
user_id

Controller:
class ProbaController < ApplicationController
  layout false

  def index
    subj = Subject.find(1)
    dozs = subj.dozents
    render :text=>"Hello World #{dozs}"
  end
end

ruby 1.8.5
rails 1.2.3
Windows

Wenn I call this controller, I get:

ActiveRecord::StatementInvalid in ProbaController#index
Mysql::Error: #42S22Unknown column 'subjects_users.dozent_id' in 'on
clause': SELECT * FROM users  INNER JOIN subjects_users ON users.id =
subjects_users.dozent_id WHERE (subjects_users.subject_id = 1 ) AND (
(users.`type` = 'Dozent' ) )
RAILS_ROOT: C:/work/unitas/config/..

Application Trace | Framework Trace | Full Trace
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract_adapter.rb:128:in
`log'
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/mysql_adapter.rb:243:in
`execute'
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/mysql_adapter.rb:399:in
`select'
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in
`select_all'
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:427:in
`find_by_sql'
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:997:in
`find_every'
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:418:in
`find'
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations/has_and_belongs_to_many_association.rb:67:in
`find'
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations/association_collection.rb:159:in
`find_target'
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations/association_proxy.rb:131:in
`load_target'
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations/association_proxy.rb:122:in
`method_missing'
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations/has_and_belongs_to_many_association.rb:91:in
`method_missing'
#{RAILS_ROOT}/app/controllers/proba_controller.rb:7:in `index'
-e:3:in `load'
-e:3

Also settings in my models don't work, and rails tries to join on
subjects_users.dozent_id field.

Is it a bug?
This topic is locked and can not be replied to.