Reference Schema field from seed file

Hi,
I have this kind of seed files to bulk into the DB.
User:

import Seedex

seed Database.User, [:email], [
    %{
        first_name: "Name1",
        last_name: "Lastname1",
        email: "user1@test.co",
        role: "user",
    },
    %{
        first_name: "Name2",
        last_name: "Lastname2",
        email: "user2@test.co",
        role: "user",
    }
]

Account:

import Seedex

seed Database.Account, [:public_key], [
    %{
        public_key: "GCB7SE6VAXMMPLJ5ZAIFPQ3HAMJGON67DNRNBK4HTJFFKHQ2QEBH4VP3",
        user_id: "",
        type: "type"
    },
    %{
        public_key: "GA2Q3VIRJ46WNQ3BJHYNFKCWJ33Q3VMOFVLCDXRNTLLRM6L2WKLYEGXS",
        user_id: "",
        type: "type"
    }
]

I need in the accounts seed, to reference the user_id (primary key) to put each use_id in that field since is an auto generated field, but I have readed about seeds but I wasn’t able to find a way to reference the field.
Any one could help me?

Thanks in advice

Why would you use a library if you don’t get any automation?

Use the normal seed with your actual functions from phoenix it’s much easier.

Have a look here https://www.phoenixframework.org/blog/seeding-data

1 Like