Sha256: 2c3f57e9a13e8a5ab4e81112e1365792e1f9ca120c5599f27f4e4098bf70f0e2

Contents?: true

Size: 648 Bytes

Versions: 3

Compression:

Stored size: 648 Bytes

Contents

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

<%- 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

3 entries across 3 versions & 1 rubygems

Version Path
statesman-3.3.0 lib/generators/statesman/templates/active_record_transition_model.rb.erb
statesman-3.2.0 lib/generators/statesman/templates/active_record_transition_model.rb.erb
statesman-3.1.0 lib/generators/statesman/templates/active_record_transition_model.rb.erb