I am developing a ERP for a small cooperative with special needs (that'y why they need a non-general solution).

I'd like to model the following: A "receipt" can either be incoming or outgoing For that I'd like to have three tables: collection | payment | receipt So a receipt can belong to a Collection or a Payment

I'd like to model the Receipt table with id, collection_id (fk), payment_id (fk) so there would be a 0,1:n relation from both father tables to the receipt table.

Does that make sense from a DB development view? Or is there another recommended way to model multiple inheritance?

The same question applies to a a document (image, PDF, etc.) - any uploadable resource: A document can either belong to an activity, a receipt, a project, etc.


I would Simply add a receipt_id to the collection and payment table.

This is a better design (objectively normalised) that allows your model to grow should your requirements change

This would solve the problem for your document model also - activity, reciept, project would contain a document_id, and you could expand your model to include any number of tables containing a document_id.

If you need to differentiate between documents stored in the table itself, you could add a document_type to make that distinction.

  • got it... problem is that this would allow only 1:1 relationships but I understand the general idea. In my usecase a payment could be for several receipts (for example you bought 3 things for a project, in 3 different stores, but the company pays you the total amount back). I guess it's better to normalize collection and payment in one table "account movement" which then can be associated to several receipt_id's Jun 3 '19 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.