Add order on deep cloning has_many associations
Currently when cloning a record with has_many associations, the order of the value of primary key of the associated records is not preserved. PostgreSQL and sqlite3 don't guarantee the order of the primary keys in the result set unless an ORDER BY clause is used.
I experience the same issue
@koki-miyazaki wdyt about ^^ ?
@moiristo Hi, could you have a look at the PR? Thanks!
Hi, thanks for the PR. Could you elaborate on why the order is important on duplication? And if so, would defining a scope on the association work as well?
has_many :things, -> { order(:id) }, dependent: :destroy
Could you elaborate on why the order is important on duplication?
I have example project with sub-entities that I copy into each new user account. It's important to create the example identical to original with the same tasks and other items order.
And if so, would defining a scope on the association work as well?
Good question. I'm considering it, but I'm hesitant because it's an old and complex project. Updating the main associations just for one small, specific case doesn't seem justified at this point.
would defining a scope on the association work as well?
It should work 👍 But the order is for cloning record, so implementing it in deep_cloneable is not so bad idea? How do you think? @moiristo
why the order is important on duplication
In my project there is a relation a campaign has_many prizes, the prizes are shown ordered by id on UI. Cloning campaign should not change the order in UI for UX.