Re: Structuring Active Record relationships

RichardOnRails
Wed, 12 May 2010 01:22:30 -0000

Thinking about it some more,  I now think I should have separate
Expense, Vendor and Account tables with the following relationships:

class Expense
	has_one Vendor

class Vendor
	has_many Accounts
	belongs_to Expense

class Account
	belongs_to Vendor

Then an Expense record can get Accounts through Vendor. .. or
something like that.

Am I getting warmer?

Thanks in Advance,
Richard

On May 11, 8:57 pm, RichardOnRails
<RichardDummyMailbox58...-FtJgd9dCuO3JTKoYRCtP1UEOCMrvLtNR@public.gmane.org>
wrote:
> 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,
> Richard