Raswidr
Raswidr

Reputation: 184

How to use the 'ranked-model' gem with MTI?

I want to use the 'ranked-model' gem with Multiple Table Inheritance.

My use case looks like this:

    class MitarbeiterListeEintrag < ActiveRecord::Base
    end
    
    class Mitarbeiter < MitarbeiterListeEintrag
      set_table_name "mitarbeiter"
    end
    
    class MitarbeiterTrenner < MitarbeiterListeEintrag
      set_table_name "mitarbeiter_trenner"
    end
    
    class CreateMitarbeiter < ActiveRecord::Migration
      def change
        create_table :mitarbeiter do |t|
          t.references :team, null: false
          t.string :vorname, null: false
          t.string :nachname, null: false
          t.string :geburtsdatum, null: false
          t.integer :sort_order, null: false
        end
      end
    end
    
    class CreateMitarbeiterTrenner < ActiveRecord::Migration
      def change
        create_table :mitarbeiter_trenner do |t|
          t.references :team, null: false
          t.string :name, null: false
          t.integer :sort_order, null: false
        end
      end  
    end

Mitarbeiter and MitarbeiterTrenner are two different tables but they share the sort order as they are displayed in the same list.

Upvotes: 0

Views: 80

Answers (1)

Tibic4
Tibic4

Reputation: 3767

To use the 'ranked-model' gem I need to add the following to the MitarbeiterListeEintrag model:

class MitarbeiterListeEintrag < ActiveRecord::Base
  include RankedModel
  ranks :sort_order
end

Upvotes: 0

Related Questions