Sha256: fe8c3f0d02ff2b09782a901e2c848240a15432b90c45ae079a203fc6ce967ba7

Contents?: true

Size: 963 Bytes

Versions: 35

Compression:

Stored size: 963 Bytes

Contents

class <%= klass %> < <%= Statesman::Utils.rails_5_or_higher? ? 'ApplicationRecord' : 'ActiveRecord::Base' %>
  include Statesman::Adapters::ActiveRecordTransition

  # If your transition table doesn't have the default `updated_at` timestamp column,
  # you'll need to configure the `updated_timestamp_column` option, setting it to
  # another column name (e.g. `:updated_on`) or `nil`.
  #
  # self.updated_timestamp_column = :updated_on
  # self.updated_timestamp_column = nil

<%- unless Statesman::Utils.rails_4_or_higher? -%>
  attr_accessible :to_state, :metadata, :sort_key

<%- end -%>
  belongs_to :<%= parent_name %><%= class_name_option %>, inverse_of: :<%= table_name %>

  after_destroy :update_most_recent, if: :most_recent?

  private

  def update_most_recent
    last_transition = <%= parent_name %>.<%= table_name %>.order(:sort_key).last
    return unless last_transition.present?
    last_transition.update_column(:most_recent, true)
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
statesman-12.1.0 lib/generators/statesman/templates/active_record_transition_model.rb.erb
statesman-12.0.0 lib/generators/statesman/templates/active_record_transition_model.rb.erb
statesman-11.0.0 lib/generators/statesman/templates/active_record_transition_model.rb.erb
statesman-10.2.3 lib/generators/statesman/templates/active_record_transition_model.rb.erb
statesman-10.2.2 lib/generators/statesman/templates/active_record_transition_model.rb.erb
statesman-10.2.1 lib/generators/statesman/templates/active_record_transition_model.rb.erb
statesman-10.2.0 lib/generators/statesman/templates/active_record_transition_model.rb.erb
statesman-10.1.0 lib/generators/statesman/templates/active_record_transition_model.rb.erb
statesman-10.0.0 lib/generators/statesman/templates/active_record_transition_model.rb.erb
statesman-9.0.1 lib/generators/statesman/templates/active_record_transition_model.rb.erb
statesman-9.0.0 lib/generators/statesman/templates/active_record_transition_model.rb.erb
statesman-8.0.3 lib/generators/statesman/templates/active_record_transition_model.rb.erb
statesman-8.0.2 lib/generators/statesman/templates/active_record_transition_model.rb.erb
statesman-8.0.1 lib/generators/statesman/templates/active_record_transition_model.rb.erb
statesman-8.0.0 lib/generators/statesman/templates/active_record_transition_model.rb.erb
statesman-7.4.1 lib/generators/statesman/templates/active_record_transition_model.rb.erb
statesman-7.4.0 lib/generators/statesman/templates/active_record_transition_model.rb.erb
statesman-7.3.0 lib/generators/statesman/templates/active_record_transition_model.rb.erb
statesman-7.2.0 lib/generators/statesman/templates/active_record_transition_model.rb.erb
statesman-7.1.0 lib/generators/statesman/templates/active_record_transition_model.rb.erb