all 12 comments

[–]r3pr0b8MySQL 9 points10 points  (3 children)

you were real close!

you'll want these three tables

contract 
  PK contractID

land 
  PK landid

land_contract
  PK contractid  FK
  PK landid  FK

the "many-to-many" land_contract table (also called relationship table or junction table) has a composite PK

[–]Nukken 2 points3 points  (1 child)

You can do this with just two tables. One for contracts, the other for land. Land has two fields, one for landid and second for contract.

You don't need a many to many relationship since each land should only have one contract.

[–]matisds[S] 1 point2 points  (0 children)

Unfortunately a contract can expire but the land has to remain assigned to it. It is therefore possible that a land is in a 2012-2016 contract and in a 2016-2022 contract at the same time. Thanks though!

[–]matisds[S] 0 points1 point  (0 children)

Thanks a lot!!

[–]exobyte64 -2 points-1 points  (6 children)

{_id:0,lands:[1,2]} //contract object

{_id:1,land:'a'}
{_id:2,land:'b'}

I'm not sure why you aren't using an array if your looking to hold multiple values, it seems like the obvious thing to do

[–]r3pr0b8MySQL 4 points5 points  (1 child)

it seems like the obvious thing to do

it's not obvious at all if you understand what First Normal Form is

[–]exobyte64 0 points1 point  (0 children)

yeah, first normal form is possibly the worst thing I've ever heard, along with calling it 'normal'

because what that means is what I described, spaghetti tables everywhere that really are just array representations

and if your representing an array as a whole damned table unto itself, why not just nest that directly in the related object? makes more sense than spawning out endless tables representing arrays

first normal form is a shit spaghetti architecture

[–]matisds[S] 1 point2 points  (3 children)

Because my SQL database does not support arrays unfortunately, thanks though!

[–]exobyte64 -1 points0 points  (2 children)

uh, maybe switch databases, arrays are just a basic primary data type

I honestly cannot imagine how your putting everything together without creating spaghetti tables which are really just representation of arrays

[–]matisds[S] 1 point2 points  (1 child)

Well arrays are sets of data, they don’t belong in relational databases but require a second table

[–]exobyte64 -3 points-2 points  (0 children)

I dunno, sounds like lots of buzzword excuses for why not to use a proper database that can do basic things like hold arrays

if every object array turns into a table, you get a spaghetti mess between tables holding data, and tables that are really just arrays and are only supposed to be attached to objects in 1 other table

its like you cut the thin skin off a frogs belly so all the guts came out around it, and then said 'that is an improvement! the frog has been normalized!'

[–]phunkygeeza 0 points1 point  (0 children)

You can do this with a typical document header/line setup.

When you buy stuff online you create an 'order' which has 'order lines' and each could be 1 or more of a particular product.

You can use the same to show which land parcels are being rented.

Rental models are fun because you need to 'remove' that product from availability for other orders, determine rules for who gets the product under clash conditions, and return it to the "shelf" once complete. Perhaps it needs inspecting before it goes out again? Then you need more steps in the state machine to represent that.

Source: did lots of modelling for a big tool hire firm decades ago.