I have two models joined through a foreign_key attribute which they both share.
# app/models/building.rb
belongs_to :building_basic_info, primary_key: "name", foreign_key:"name"
# app/models/building_basic_info.rb
has_many :buildings, primary_key: "name", foreign_key:"name"
I'm trying to write a Factory that will create both a building and a building_basic_info and associate them through the attribute name.
FactoryGirl.define do
factory :building do
name "cannon"
factory :building_with_bbi do
name "cannon"
end
end
end
building = build_stubbed(:building)
building.building_basic_info
# => nil... but I want it to return the associated building_basic_info object
Any help is greatly appreciated.
FactoryGirl.define do
factory :building do
name "cannon"
association :building_basic_info
end
factory :building_basic_info do
name "cannon"
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With