Question about database setup: Is it bad to have NULL entries?


I started developing a web app in rails and a friend of mine helped me getting started. I know a fair bit about databases and ruby, so no problem there. But the thing is: I don't have a clue about conventions and best practices.

So here's the relations in question:

User <-> Ledger <-> Activity

One User has one or more ledgers and a ledger belongs always to one user.
A ledger has zero to N activities and an activity has _two_ ledgers (a creator and an involved one).

So here's the deal: A if you transfer Money from a ledger (your wallet, for example) to a friend, the creator is you and the involved one is your friend. Your friend is not registered in the application, so a ledger gets created (implicitely) and there goes the money.

What my problem is now: My friend proposed that each ledger has to belong to a user account, so the ledger isn't "dangeling" around or something. In the upper example, the "my friend"-ledger would belong to the user himself - which is semantically wrong.

What I'd suggest is that a ledger can belong to a user, but doesn't have to. So one could implicitely create ledgers by creating money transfers (activities) to them - but my friend calls this inconsistency with the database, as a ledger could now have a NULL reference in the belongs-to-user field.

What is the best practice here? My idea is, in my opinion, semantically more correct - but as I said, I have no clue about best practice.

1 thought on “Question about database setup: Is it bad to have NULL entries?”

  1. If you’re implicitly creating ledgers, why not also implicitly create users to own them?

    If you can relax the restriction that ledgers must have 1 user, why can’t you relax the restriction that activities must have 2 ledgers?


Leave a Comment