0

I have 3 models:

  • state_records, has_many :weight_categories,
  • weight_categories, has_many :lifts,
  • state_records, has_many :lifts, through: :weight_categories

The form for @state_record includes both the creation of weight_categories and lifts via the cocoon gem. Each @weight_category has 3 lifts but these lifts need to be in a specific order.

When I create the form everything is OK. When I update the form (only in production), occasionally the order of the lifts will change. I don't have anything in the code to define the order because I assumed it would order itself by created_at. Everything works fine in development but not in production. I assume it has something to do with having postgres as my production database and sqlite3 as my dev database.

I think I need to just define the order but don't know the best way to do this. Everything gets displayed through the State Record's model.

Vasilisa
  • 4,604
  • 3
  • 20
  • 25
BB123
  • 215
  • 3
  • 10
  • https://stackoverflow.com/questions/18284606/deprecated-warning-for-rails-4-has-many-with-order/18284635#18284635 – Alexander Azarov Mar 01 '19 at 18:42
  • @AlexanderAzarov any suggestions on how to go about making sure the lifts are in the correct order when updated? – BB123 Mar 02 '19 at 22:19
  • ActiveRecord does not change `created_at` when updating records. So, if you sort records by `created_at` and are **updating** records, then you shouldn't observe any changes in order. So, if you still see the changes, then some of these assumptions are wrong or you are doing something differently. – Alexander Azarov Mar 03 '19 at 08:30

0 Answers0