module Sidekiq
  module Superworker
    class Subjob < ActiveRecord::Base
      attr_accessible :jid, :subjob_id, :superjob_id, :parent_id, :children_ids, :next_id,
        :subworker_class, :superworker_class, :arg_keys, :arg_values, :status, :descendants_are_complete,
        :meta if ActiveRecord::VERSION::MAJOR < 4

      serialize :arg_keys
      serialize :arg_values
      serialize :children_ids
      serialize :meta

      validates_presence_of :subjob_id, :subworker_class, :superworker_class, :status

      def relatives
        self.class.where(superjob_id: superjob_id)
      end

      def parent
        return nil if parent_id.nil?
        relatives.where(subjob_id: parent_id).first
      end

      def children
        relatives.where(parent_id: subjob_id).order(:subjob_id)
      end

      def next
        relatives.where(subjob_id: next_id).first
      end

      def to_info
        "Subjob ##{id} (#{superworker_class} > #{subworker_class})"
      end
    end
  end
end

module Sidekiq
  module Superworker
    class Subjob < ActiveRecord::Base
      attr_accessible :jid, :subjob_id, :superjob_id, :parent_id, :children_ids, :next_id,
        :subworker_class, :superworker_class, :arg_keys, :arg_values, :status, :descendants_are_complete,
        :meta if ActiveRecord::VERSION::MAJOR < 4 || ActiveRecord.constants.include?(:MassAssignmentSecurity)

      serialize :arg_keys
      serialize :arg_values
      serialize :children_ids
      serialize :meta

      validates_presence_of :subjob_id, :subworker_class, :superworker_class, :status

      def relatives
        self.class.where(superjob_id: superjob_id)
      end

      def parent
        return nil if parent_id.nil?
        relatives.where(subjob_id: parent_id).first
      end

      def children
        relatives.where(parent_id: subjob_id).order(:subjob_id)
      end

      def next
        relatives.where(subjob_id: next_id).first
      end

      def to_info
        "Subjob ##{id} (#{superworker_class} > #{subworker_class})"
      end
    end
  end
end

Check for MassAssignmentSecurity when determining whether to call attr_accessible
Check for MassAssignmentSecurity when determining whether to call attr_accessible

AR 4 may require attr_accessible if the protected_attributes gem is installed