Reputation: 29514
i am getting some problem in Fixtures
I am having models advantage and kind
advantage.rb
belongs_to :kind
kind.rb
has_many :advantages
advantages.yml
1.
id: 1
title: something
kind: apple
kind_id: 1
2.
id: 2
title: somethjin
kind: orange
kind_id: 2
kinds.yml
apple:
id: 1
name: apple
orange:
id: 2
name: orange
I am trying to bring association here as kind_id is coming with some junk values
so i did like
kinds.yml
apple:
name: apple
orange:
name: orange
and in advantages.yml
something:
title: something
kind: apple
somethjin
title: somethjin
kind: orange
But it didn't work
How to resolve this
Upvotes: 5
Views: 2302
Reputation: 9771
It is not an answer for your question. But i always use Factories instead of fixtures. It is much easier to maintain and associations are easy.
Take a look here: https://github.com/thoughtbot/factory_girl
Upvotes: 1
Reputation: 5791
Try like this but not sure:
kinds.yml apple: id: 1 name: 'name1' orange: id: 2 name: 'name2' advantages.yml adv1: id: 1 title: 'title1' kind: apple
Upvotes: 1