So we're having an issue with a music player. We have 3 models involved into this:
User, Song, Play
Play:
user_id,
song_id,
played_at,
So when a user is in the music player and hits the "next" btn, a new Play model is created with a new song for them to listen. To know the order of the queue we are using the played_at field. And the problem comes now. Sometimes, users are quick enough to create Play records that have the same played_at, in the same exact second. Imagine pressing the next btn quickly until the user gets the song they want. So yeah, then, if presses the "back" button (to go to previous record being played), it bugs out and doesnt show the correct song that was played before cuz of the exact same played_at field's value!
How would u solve this issue? I thought about adding microseconds on played_at field, so its impossible that the user creates more than one play having the same exact value.
I ask how would u solve it cuz im unsure if modifying the MySqlGrammar to set the date format like this is a great idea or can introduce unexpected behaviours - 'Y-m-d H:i:s.u'