Single Table Inheritance and HABTM Problem


#1

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:inexecute’
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:inselect_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:infind_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:infind’
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:inload_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:inmethod_missing’
#{RAILS_ROOT}/app/controllers/proba_controller.rb:7:in index' -e:3:inload’
-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?