Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it bad to have meaningless keys in my domain model classes?

When creating domain model, we almost always have Id field or property for our entities which represents the primary key column of corresponding table in the database. My question is - if I have this key property that has nothing to do with the domain model (in other words, it's just database concern; Martin Fowler prefers to name it meaningless key), is persistence layer leaking into my domain? And if it is, how do I prevent it?

like image 596
chester89 Avatar asked Dec 18 '25 08:12

chester89


1 Answers

Look at the problem another way: Will hiding the Primary Keys make it easier for your team to develop the solution, or make it even harder?

Don't worry about PK values 'leaking' into your entities - I'm sure your software has bigger problems that need to be solved.

like image 174
Vijay Patel Avatar answered Dec 21 '25 18:12

Vijay Patel