I have a users
table and a one-to-zero/one relation with a businesses
table (users.user_id => businesses.user_id). On my users
table I have a discriminator which tells me if the user is of type business and therefore I need to have details on the businesses
table as well.
I want to create my Users with my factory which currently is working and then only create business details where the discriminator points to a business account.
I have three options in my mind:
- Create from users factory and then using '->each()' do some checks on the discriminator and create a new business user using a the factory. However I cannot pass to the business factory the
user_id
that the user was assigned. - 首先创建用户.然后在我的业务seeder 中,检索与"业务"鉴别器匹配的所有用户.然后为所有这些用户运行一个创建业务细节的工厂.但同样,我必须以某种方式将已经创建的用户的
user_id
与business factoryuser_id
联系起来. - In my business factory, create a new User and retrieve the id, thus making the link between
users.user_id
andbusiness.user_id
. However I am using a random generator foruser.user_type
so even if I have thebusinesses
table filled it might be for users that have the discriminator as 'personal'.
还有别的办法吗?我能把我的 seeder 机传给工厂吗?