Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Atef95's avatar

Relationship design

Hey guys

I've one question

I'm working on a ressource called Book

Each book in the system can be either digital or/and paper..

we can set a price for digital as well as for paper..

we can set if it's free or not for digital case..

in this situation , do I have to create another entity Version and link it to Book ?

or gather them up in Book entity ?

for the case of price , if it's free I limit on the price field itself or I create a boolean field ?

Thank you !

0 likes
3 replies
nicks's avatar

It depends. Can the price change over time, and do you need to keep track of the price changes?

If you don't need to track the price changes, you can go ahead and insert paper_price and digital_price fields in your Book entity. If you need to track the price changes, you will need these in a separate entity, with one record for the paper_price over a certain period, and one record for the digital price over a certain period.

If a version is free, why not just set price to 0.00?

1 like
Atef95's avatar

@nicks

Thank you for your answer!

at this moment I don't have any need for tracking prices.. I will just fill them..

but what rolls in my mind is the future change requests and extensibility..

nicks's avatar

If you are concerned about future change requests, then use a separate entity. This is the correct way to do this, and will provide far more flexibility for the future.

But it's slightly harder to code, as you have to ensure you create/update all records in your controllers. Ensure relational integrity through the use of database transactions, so that if you get an error updating one table, all the updates are rolled back.

My suggestion of using two separate fields is really just a hack to handle a simple requirement.

1 like

Please or to participate in this conversation.