mercredi 26 décembre 2018

Add a model in the present in the other namespace as foreign key

In Rails I want to include a model_id as foreign key into another model which is present in another namespcae. I have two models as
First:

class Garment < ApplicationRecord
end

Second:

class Superadmin::Company < ApplicationRecord
end

I am using the following command for it.

 rails g migration addCompanyIdToGarment company:references

which give output like:

class AddCompanyIdToGarment < ActiveRecord::Migration[5.0]
  def change
    add_foreign_key :garments, :company
  end
end

which is incorrect, please provide the correct command or procedure to do it.

Aucun commentaire:

Enregistrer un commentaire