如何在Rails模型中创建实例(在数组中)?

时间:2019-07-17 20:47:25

标签: ruby-on-rails instantiation

我有两个模型attributeTypeperson。我想在数组中创建attributeType类的实例,然后在person类的实例中创建

attributeType (id, name)
person(name, attributeType)

实例如下:

instance of attributeType is => attribute (id, value)
instance of person is => pers (attribute, name)

请问如何创建所有内容?

我的person模型:

class Person < ApplicationRecord
    self.primary_key = "id"
    has_many :attributeTypes , :through => :person_has_attributeTypes, dependent: :destroy
    end

我的attributeType模型:

class AttributeType < ApplicationRecord
     has_many :persons, :through => :person_has_attributeType, dependent: :destroy
    end

0 个答案:

没有答案