Structuring Active Record relationships

RichardOnRails
Wed, 12 May 2010 00:57:22 -0000

Hi,

I have three tables: Expenses, Vendors and Vendor _Accounts

It should operate as follows:
When a new Expense record is created,
A vendor is selected from a drop-down of Vendors and,
An account is selected from a drop-down of Vendor_Accounts where
Vendor_Accounts#vender == selected vendor

So I should have a structure something like:
class Expense
	has_one Vendor

class Vendor
	has_many Vendor_Accounts where Vendor#id == Vendor_Accounts#vendor
	belongs_to Expense

class Vendor_Account
	belongs_to Vendor

I don’t think I should have Expense, Vendor and Account tables because
the accounts defined by each vendor bear no relationship with the
other vendors’ account beyond the mere concept of “account”.

Does this make sense, and if so,  how precisely should I describe
these relationships? Am I close with the above idea?

BTW, I''m running Rails 2.3.5, Ruby 1.8.6, WinXP-Pro/SP3, Firefox
3.6.2, Firebug 1.5.3,
MySQL 5.0.37-community-nt, Mongrel, Apache HTTP Server 2.2.15

Thanks in Advance,