Reputation: 605
I am writing a project for, let's say, a company that maintains multiple real estate projects throughout the city. In this way, they have:
So, the address of #1 will be Main street - 28, address of #2 will be Main street - 28, building 4 and address of #3 will be Main street - 28, building 4, apt. 12.
The problem that they also have some single houses that are actually as #1 and #2 at the same time (like Another street - 123 (and lots of apartments)).
I am struggling to design a DB schema for this and have multiple variants:
id | address |
---|---|
1 | Main street - 28 |
2 | Main street - 28 building 1 |
3 | Main street - 28 building 1 apt. 12 |
The problem is that since there might not be the middle section (no main address extension, like building 4
), I'm afraid the last variant won't work as expected, since each apartment will be attached to it.
Would really appreciate your help!
Kind regards,
Upvotes: 0
Views: 184
Reputation: 605
Found the way this could be achieved. I used one of many laravel packages for Nested Set Model structure implementation. In this case, I will have the tree-like model in database, where there are parents and descendants.
In this way, I can refer to every parent element even if I have retrieved only the deepest child element of the root. This also allows multiple operations, like counting up/down (parents/children), as well as building an actual visualized tree model.
There are multiple Laravel packages for achieving this.
Upvotes: 0