私はOrganizationとPackage_ipのモデルを持っています。Rails - 多相関連には多くの関係インデックス値があります
団体は以下のとおりです。
組織
has_many :ips, as: :ipable, class_name: Package::Ip
accepts_nested_attributes_for :ips, reject_if: :all_blank, allow_destroy: true
パッケージ:: Ipの
belongs_to :ipable, :polymorphic => true, optional: true, inverse_of: :ip
Package_ips表はあります
create_table "package_ips", force: :cascade do |t|
t.string "identifier"
t.text "description"
t.text "conditions"
t.integer "ipable_id"
t.string "ipable_type"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "title"
t.string "status"
t.string "classification"
t.index ["ipable_type", "ipable_id"], name: "index_package_ips_on_ipable_type_and_ipable_id", unique: true, using: :btree
end
私の目標は、CRへの組織のためでありますpackage_ipの多くのインスタンスを作成します。
ただし、インデックスの仕組みには問題があります。 package_ipの2番目のインスタンスを作成する場合、インデックス値がもはや一意ではないというエラーが表示されます。
私のインデックスからユニークな制約を削除してもよろしいですか?私はipable_ipがorganisation.idになり、ipable_typeが親クラス(組織)になることを認識しています。私はそれがなぜユニークである必要があるのか分かりません。しかし、多分多様な関連性とインデックスへの依存について何かを忘れているかもしれません。
あなたの例が何を意味するのか分かりません。私はOrganisation.ipsをテストしたいので、その組織で作成されたIPインスタンスの配列を返すようにします。 – Mel
注意すべき事項のいくつかの例を更新しました。 – EnabrenTane