For the most part I'm working my through creating AR associations with a legacy DB using the various options AR provides to identify tables and fields.
My current snag is a little outside of that stuff.
I have a Company--with an account_manager attribute which is the ID of a User. So..
class Company belongs_to :account_manager, :class_name =>'User', :foreign_key => "account_manager"
The User table has an autoinc ID, so that part works out.
This works fine for pulling the account_manager's name in a Company.find
But... when trying to save a new Company record, I get the following error.
User(#blabla) expected, got String(#blabla)
OK. Expected what? And since I am saving a Company model, why is User complaining?
account_manager is allowed to be NULL, and no data is being assigned to the attribute prior to the save.
If I comment out the Company#belongs_to to eliminate the association, then the save works fine.
I added
class User has_many :companies, :class_name => 'Company', :foreign_key => 'account_manager'
to reciprocate the association, but that makes no difference.
Googled, read my books, rails guides, but I'm stymied.
All suggestions appreciated. Thx.
-- gw