Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fixtures with associations in rails

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

like image 311
useranon Avatar asked Nov 14 '22 02:11

useranon


1 Answers

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
like image 68
Ashish Avatar answered Nov 23 '22 23:11

Ashish