Hi Daniel
Thanks for helping
This is exactly how I was thinking it should work. But I just tried
using set_table_name and I still got the same result, for example, using
your code (which is exactly what I'd love to do), I get this:
w = Worker.create(:name => "WorkerName") # ok
p = Person.create(:name => "PersonName") # ok
ac = AnotherClass.create # ok
ac.worker = w # here i got the error! like:
# ActiveRecord::StatementInvalid: Mysql::Error: Unknown column
'person.another_class_id' in 'where clause': SELECT * FROM `person`
WHERE (`person`.another_class_id = 1) LIMIT 1
It still goes to the parent class to search for the relational id.
"set_table_name" works for you in this particular case? could it be the
activerecord version I use? My gems are:
actionmailer (2.3.9)
actionpack (2.3.9)
activerecord (2.3.9)
activeresource (2.3.9)
activesupport (2.3.9)
builder (2.1.2)
capistrano (2.5.19)
highline (1.6.1)
i18n (0.4.1, 0.3.7)
json (1.4.6)
json_pure (1.4.6)
multi_json (0.0.4)
mysql (2.8.1)
net-scp (1.0.3)
net-sftp (2.0.5)
net-ssh (2.0.23)
net-ssh-gateway (1.0.1)
pg (0.9.0)
racc (1.4.6)
rack (1.1.0)
rails (2.3.9)
rake (0.8.7)
rspec (1.3.0)
text-format (1.0.0)
text-hyphen (1.0.0)
tmail (1.2.7.1)
tzinfo (0.3.23)
will_paginate (2.3.14)
And the trace when I get the error:
from /usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.9/lib/active_record/connection_adapters/abstract_adapter.rb:227:in `log'
from /usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.9/lib/active_record/connection_adapters/mysql_adapter.rb:324:in `execute'
from /usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.9/lib/active_record/connection_adapters/mysql_adapter.rb:639:in `select'
from /usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.9/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all_without_query_cache'
from /usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.9/lib/active_record/connection_adapters/abstract/query_cache.rb:62:in `select_all'
from /usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.9/lib/active_record/base.rb:665:in `find_by_sql'
from /usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.9/lib/active_record/base.rb:1582:in `find_every'
from /usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.9/lib/active_record/base.rb:1539:in `find_initial'
from /usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.9/lib/active_record/base.rb:617:in `find'
from /usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.9/lib/active_record/associations/has_one_association.rb:81:in `find_target'
from /usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.9/lib/active_record/associations/association_proxy.rb:236:in `load_target'
from /usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.9/lib/active_record/associations/association_proxy.rb:113:in `reload'
from /usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.9/lib/active_record/associations.rb:1256:in `worker'
from (irb):2
Regards,
Javi Ruiz