小编Har*_*lap的帖子

"协会期望,得到字符串"与多对多关联

目前我在Rails 3中创建类似"体育管理和结果收集应用程序"的东西.在这个应用程序中,我需要创建几个练习本身可以有多个"结果类型"(心率,距离,公里,重复,...).并且应该可以按照我的首选顺序排列结果类型.所以,这是一种经典的多对多关系.

我提出了以下迁移:

    class CreateExercises < ActiveRecord::Migration
      def self.up
        create_table :exercises do |t|
          t.integer :user_id
          t.string :name
          t.text :beschreibung
          t.integer :resulttype_id
          t.boolean :active, :default => true
          t.timestamps
        end
      end
      def self.down
        drop_table :exercises
      end
    end

    class CreateResulttypes < ActiveRecord::Migration
      def self.up
        create_table :resulttypes do |t|
          t.string :name
          t.string :einheit
          t.text :beschreibung

          t.timestamps
        end
      end

      def self.down
        drop_table :resulttypes
      end
    end

    class CreateExercisesResulttypesJoin < ActiveRecord::Migration
      def self.up
        create_table :exercises_resulttypes, :id => false do |t|
          t.integer "exercise_id"
          t.integer "resulttype_id"
        end
        add_index :exercises_resulttypes, …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails ruby-on-rails-3

4
推荐指数
1
解决办法
2672
查看次数

标签 统计

ruby ×1

ruby-on-rails ×1

ruby-on-rails-3 ×1