Reputation: 3197
I'm creating a database structure that contains property listings. Each listing contains various amenities that I need to store, in a listing_amenities table.
This listing_amenities table will contain recursive records. For eg. A listing amenity might be "internet". Under this record we need to store children records such as what kind of internet it is (ADSL, Fibre etc.), the speed (20mbs, 50mbs etc.), as well as the ISP.
My question is whether a recursive model is the right solution here and how I would go about building the database structure for this or if there is a better solution for this kind of problem. In other words, would it be better to simply store all the amenities and their sub_properties in a big JSON blob column on the listings table?
The reason for creating a recursive table is to make querying better so that eventually we can easily query for property listings that have ADSL internet, for example, and sort this by location so that we could possibly target specific areas for marketing purposes to upgrade to fibre.
Upvotes: 0
Views: 165
Reputation: 10089
First, I would recommend against a JSON BLOB, because that will not be easy and reliable to query.
If you identify a finite number of levels you are breaking down your sub_properties into, like two for amenity and sub_property, that will make it easier to deal with.
The reason to use one table, with self references to sub- or super- properties would be to support an indefinite number of levels you can break things down by. However, that may be cumbersome, because you never know how many levels there are, so you don't know how many levels to use in a join. If you can avoid this, it might be better.
Upvotes: 1