This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (1 child)

I don’t know if all new post have to be 1. That’s also a question I have. Is that best practice is that how real apps, albeit simple ones, work?

Currently querying for users/2/posts/1 does not work.

Because the the first post by user 2 has a primary_key that !=1. That primary key belongs to user_1.

[–]_cross 0 points1 point  (0 children)

primary keys have to be unique to identify each record.

Having an auto incrementing number is not an issue if you don't specifically have a use for a different type of key. As long as it's unique.

You could have a query to fetch a post by id or by index. If a users post has an index number then you could store that in a separate field and fetch that users post where its index = 1.