[Rails] 2 models with multiple relationships

Timothy Johnson timothy at ventureinteractive.com
Wed Aug 16 12:13:25 GMT 2006


I am in the middle of building YARELS (Yet Another Real Estate Listing 
Site), and here is one of my issues with model relationships.

I have to core models and DB tables:

User
Property

Here are the relationships I need to express:

A user can have many properties that he owns (he is the seller)
A user can have many properties on his favorites list (he is a 
buyer/seeker)
A user can have many properties that he manages (he is a listing 
manager)
    * A listing manager actually has control over counties
      so if a property shows up in that county, it is his.

Property has_one seller
Property has_many watchers :through => :saved_property
Property has_one listing manager

I am just wanting to make sure that none of the lovely Rails features 
override each other. I already made a join model for SavedProperty, and 
the relationship with the listing manager could be joined through a 
table that lists the counties.

My main question is: could I be doing something better to make these 
relatioships seemless? Should I use single-table-inheritance with the 
User in order to give users specific roles (even though sellers and 
managers need to have all the same priviliges as buyers, so it could end 
up conflicting that way too).

Thanks for all your help.

Timothy Johnson
www.foundinteractive.com

-- 
Posted via http://www.ruby-forum.com/.


More information about the Rails mailing list