You are obviously reading closely .. good catch;-)
At best it's "incomplete". I think in that section the author intends to give a sense of alternatives before presenting the solution in question. And I guess it does give you enough info to know the "type" of solution he means even though it is a broken example.
I believe you were basically right first off. For that code snippet to make a complete example:
* referrals/referral_types => pick on and use in both places
* mirrored habtm in each model
i.e. yes this looks like a cut and paste error!
One way to look at stuff like this is just to map out the database. If we take the book example literally, this is what we get:
create_table :users do |t|
end
create_table :referrals do |t|
end
create_table :referral_types do |t|
t.integer :user_id
end
create_table :referrals_users, id: false do |t|
t.integer :referral_id
t.integer :user_id
end
Now that is obvioulsy an incomplete solution to what the author was discussing. But if you were given that IRL, I guess it is possible to bodge it to meet the requirement. but it needs more tables and/or columns to do so.
But the fix/solution you were suggesting I think is:
class User < ActiveRecord::Base
has_and_belongs_to_many :referral_types # this is Line_1
end
class ReferralType < ActiveRecord::Base