mardi 22 septembre 2020

Rails: How do I get reference from one .yml files to second .yml file

I have 2 models User and Account and I want to create a seed data in by using .yml file

user.rb

class User < ApplicationRecord
  has_one: account
end

and account.rb

class Account < ApplicationRecord
  belongs_to: user
end

my .yml files are

config/users.yml

user1: 
  first_name: 'John'
  last_name: 'Doe'
user2: 
  first_name: 'John'
  last_name: 'Wick'

and config/accounts.rb

account1:
  balance: 1000
account2: 
  balance: 500

so my question here is that how can i add user1 to account1 and user2 to account2 and so on. and how can i use it in seed file the create some data. Thanks :)

Aucun commentaire:

Enregistrer un commentaire