Tuesday, May 11, 2010

[Rails] Structuring Active Record relationships

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

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate