I'm about to develop a personal project for learning purpose. A real-estate web site, where advertisers (registered users) can publish ads for their properties (apartments, lands, houses, ...) either for rent (for a defined period or undefined period) or for sale. Also where clients (visitors) can search for specific type of properties for rent or purchase in a specific location.
Business rules:
- User is a registered one.
- User has one Role and only one Role (user, admin, …).
- Role belongs to many Users (default Role for each User is user).
- User has one Location and only one Location (location refer to address).
- Location belongs to many Users.
- User has many Properties (either for rent OR sell).
- Property belongs to one User.
- Property belongs to one Location (location refers to address).
- File belongs to Property.
- Property has many Files (basically images).
I did so many Google searching, seen some database modeling in databaseanswers.org but I’m stuck on property’s type/features, I can't really figure it out, I don’t know the best solution for this!! Because each type of property has different features, for example apartment has rooms, bathrooms... but lands no, for lands we could say they are in-town or out-town…
I want to design this database to be more maintainable and scalable. I don’t want the database design structure to cause more complex queries/code while developing.
I would appreciate if you could give me some advice about my “little” issue.
Do I have to separate the Type of each Property to their own Entity (table) for example Apartments table, Lands table, Houses table … That way I can attach them with their own Features.
Or do I have to merge them in one table "Properties" with all the Features, and have another table "Type" to link each Property to its Type (like in Posts and Categories).
Or do I have to create four table "Properties" "Type" "Features" and a pivot table "feature_property".
- Property belongs to one Type (Apartment, Land, House, …).
- Type has Many Properties.
- Feature has many properties.
- A property has many Features.