[Fixed]-Benefits of foreign key over integerfield

1đź‘Ť

  1. Deleted objects

If you ever decided to delete the original post, you’d need a separate query to handle whatever you expect to do with the cloned posts instead of using the on_delete kwarg of a FK.

  1. Its an extra query

As noted in the comments, foreign keys allow you to traverse the relationships directly through the ORM relationship methods.

  1. Data structure visualisation tools

These won’t be able to traverse any further down from an integer field since it will believe it is at a leaf node.

Throughout all of this though, the elephant in the room is that a “clone” is still just duplicated data so I wonder why you don’t just let a blog post be referenced more than once then you don’t need to worry about how you store clones.

👤Sayse

Leave a comment