I don’t have a class by the name of “ReviewersScoreCard”, yet my many to
many configuration looks as follows. And, these errors while running
some
simple test with ./script/console is giving me a headache:
./script/console
Loading development environment.
r = Reviewer.find_first
=> #<Reviewer:0x19d0a48 @attributes={“id”=>“1”, “first_name”=>“Big”,
“last_name”=>“Bird”}>r.candidates
=> [#<Candidate:0x19c6340 @attributes={“status”=>"", “id”=>“1”,
“sponsor”=>"", “first_name”=>“Jim”, “last_name”=>“Jeffrey”,
“reviewer_id”=>“1”}>, #<Candidate:0x19c62c8 @attributes={“status”=>"",
“id”=>“2”, “sponsor”=>"", “first_name”=>“Lam”, “jack”=>“johnson”,
“reviewer_id”=>“1”}>]r.reviewers_score_cards
NameError: uninitialized constant ReviewersScoreCard
from …dependencies.rb:195:inconst_missing' from ...association_proxy.rb:12:in
initialize’
from …has_and_belongs_to_many_association.rb:5:ineval' from ...association_proxy.rb:12:in
initialize’
from …has_and_belongs_to_many_association.rb:5:ininitialize' from ...associations.rb:753:in
new’
from …associations.rb:753:inreviewers_score_cards' from ...associations.rb:749:in
reviewers_score_cards’
Here are my models:
class Reviewer < ActiveRecord::Base
has_many :candidates
has_and_belongs_to_many :reviewers_score_cards
end
class ScoreCard < ActiveRecord::Base
has_and_belongs_to_many :reviewers_score_cards,
:join_table => “reviewers_score_cards”
end
class Candidate < ActiveRecord::Base
belongs_to :reviewers
end
What is with the reference to ReviewersScoreCard in the error message?
I did not create the model ReviewerScoreCard, but even if I did
ReviewersScoreCard
is being looked up instead. Shouldn’t the model be ReviewerScoreCard?. I
even tried creating a model by that name and received the same error.
What
am I doing wrong? I have tried all the examples I can find on the web
about
many-to-many and they all work. Any help would be greatly appreciated.
Thanks in advance,
_arwuah
Just in case. My DDL looks as follows:
DROP TABLE IF EXISTS reviewers;
CREATE TABLE reviewers (
id int unsigned not null auto_increment,
first_name varchar(60) not null,
last_name varchar(60) not null,
primary key(id)
);
DROP TABLE IF EXISTS candidates;
CREATE TABLE candidates (
id int unsigned not null auto_increment,
reviewer_id int unsigned not null default 0,
first_name varchar(60) not null,
last_name varchar(60) not null,
sponsor varchar(120) not null,
status varchar(30) not null,
constraint fk_cr_reviewer foreign key (reviewer_id) references
reviewer(id),
primary key(id)
);
–
– Table structure for table reviewers_score_cards
DROP TABLE IF EXISTS reviewers_score_cards;
CREATE TABLE reviewers_score_cards (
reviewer_id int unsigned not null default 0,
score_card_id int unsigned not null default 0,
constraint fk_rsc_reviewer foreign key (reviewer_id) references
reviewer(id),
constraint fk_rsc_score_card foreign key (score_card_id) references
score_cards(id),
primary key(reviewer_id, score_card_id)
);
–
– Table structure for table score_cards
DROP TABLE IF EXISTS score_cards;
CREATE TABLE score_cards (
id int unsigned not null
auto_increment,
appears_calm int unsigned not null default
0,
…
primary key(id)
);