Project

General

Profile

Patch #41954 » 0008-Use-record-id-for-fixture-key-id-if-exists.patch

Ko Nagase, 2024-12-13 09:24

View differences:

lib/tasks/extract_fixtures.rake
52 52
    File.open(File.join(dir, "#{table_name}.yml"), 'w') do |file|
53 53
      columns = ActiveRecord::Base.connection.columns(table_name)
54 54
      column_names = columns.map(&:name)
55
      order_columns = column_names.include?('id') ? 'id' : column_names.join(', ')
55
      has_id_column = column_names.include?('id')
56
      order_columns = has_id_column ? 'id' : column_names.join(', ')
56 57
      where_clause = table_filters.has_key?(table_name) ? "WHERE #{table_filters[table_name]}" : ''
57 58
      sql = "SELECT * FROM #{table_name} #{where_clause} ORDER BY #{order_columns}"
58 59
      data = ActiveRecord::Base.connection.select_all(sql)
......
70 71
            end
71 72
          end
72 73
        end
73
        hash["#{table_name}_#{i.succ!}"] = record
74
        key_id = has_id_column ? sprintf('%03d', record['id']) : i.succ!
75
        hash["#{table_name}_#{key_id}"] = record
74 76
        hash
75 77
      }.to_yaml
76 78
    end
(10-10/10)