Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Order of create? #37

Closed
dazoo opened this issue May 9, 2011 · 10 comments
Closed

Order of create? #37

dazoo opened this issue May 9, 2011 · 10 comments
Labels

Comments

@dazoo
Copy link

dazoo commented May 9, 2011

When I create a record with nested attributes, the nested attributes tend to be created in a seemingly random manner- I added each nested field in order, and filled them with values from 1-5. However, it gets created in a random order: => 5 3 1 2 4. It's different every time.

So then when I go edit, the form displays the fields in that order as well.. which the user might find confusing.

Is there a way to let it create the records from top to bottom?

@ryanb
Copy link
Owner

ryanb commented May 13, 2011

Hmm, I thought since it uses the current time as a creation id it would build them in that order, but I guess not. Time to investigate.

@dazoo
Copy link
Author

dazoo commented May 15, 2011

Are you experiencing this problem as well? Or did I do something wrong on my part?

@ryanb
Copy link
Owner

ryanb commented May 15, 2011

I haven't seen this behavior in the nested_form branch of the complex-form-examples project, but I haven't tested it extensively. You may want to check that out and see if you get the same behavior.

@nathanborgo
Copy link

I'm having the same problem. To reproduce:

  • Build 2 child objects in the controller
  • Don't fill the parent form out (to trigger a validation error)
  • Fill the child forms out
  • Add another child object through the link_to_add
  • Fill it out
  • Repeat that until you have 6 child objects
  • Submit
  • The child forms are now out of order (in my case: 1, 6, 3, 5, 4, 2) an no longer use the current time.

When creating the new child forms, they do use the current time. If you inspect a field after the validation error, though, they all reset to 0-5, in the wrong order. If you do the same thing, but building 1 child object in the controller instead of 2, it works fine.

Hopefully that helps.

@ryanb
Copy link
Owner

ryanb commented Jun 29, 2011

@subtractiv thanks for the detailed response. This may be an issue with how nested attributes works in Rails, but I'll research it and see if there's a way to fix it here. If someone has ideas please submit a pull request.

@dmilisic
Copy link

I can confirm this issue. However, before I used an old version where new nested fields didn't have "new_" prefix and it worked fine (I used it with up to 100 new records and the order was always the same as entered).

Could this "new_" prefix be removed? Or is it risky that new id would match existing?

@hakjune
Copy link

hakjune commented Apr 3, 2012

This problem still persists.
timestamp is used when we add new sub item in nested model but it's saved in wrong order, which should have been ordered by time.

"1333432769586"=>{"partnercomment"=>"6", "expenditure"=>"", "status"=>"1", "_destroy"=>"false", "id"=>"", "time4"=>"0", "time3"=>"0", "time2"=>"0", "time1"=>"0"},
"1333432776523"=>{"partnercomment"=>"13", "expenditure"=>"", "status"=>"1", "_destroy"=>"false", "id"=>"", "time4"=>"0", "time3"=>"0", "time2"=>"0", "time1"=>"0"},
"1333432773627"=>{"partnercomment"=>"10", "expenditure"=>"", "status"=>"1", "_destroy"=>"false", "id"=>"", "time4"=>"0", "time3"=>"0", "time2"=>"0", "time1"=>"0"},
"1333432772523"=>{"partnercomment"=>"9", "expenditure"=>"", "status"=>"1", "_destroy"=>"false", "id"=>"", "time4"=>"0", "time3"=>"0", "time2"=>"0", "time1"=>"0"},
"1333432762803"=>{"partnercomment"=>"1", "expenditure"=>"", "status"=>"1", "_destroy"=>"false", "id"=>"", "time4"=>"0", "time3"=>"0", "time2"=>"0", "time1"=>"0"},

I recently upgraded my bundles and suspect javascript timestamp saved in wrong manner after that upgrade.
Please someone take a look at the issues we are having to make the nested_form better.

@lest
Copy link
Collaborator

lest commented Sep 18, 2012

Could you please push a test application reproducing this issue? Thanks.

@mantas
Copy link

mantas commented Dec 19, 2012

I bumped into this bug recently. It seems to be not related to nested_issue. It's Rails and Ruby compatibility issue. Everything works fine with 1.9.* Rubies, but bug appears with 1.8.7. I guess this bug should either be forwarded to RoR issues or forgotten as legacy bug...

@lest
Copy link
Collaborator

lest commented Apr 8, 2013

Closing as this issue seems not being related to nested_form.

@lest lest closed this as completed Apr 8, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

7 participants