I currently have a user entity that contains multiple values as first_name
and last_name
for example.
I want to add a OneToOne relation user_informations
to my user that will contains a bio
field. (Note that I don’t want to add the bio
field directly into the user
entity )
I have created the entity using the command php bin/console make:entity userInformation
php bin/console make:entity UserInformation
created: src/Entity/UserInformation.php
created: src/Repository/UserInformationRepository.php
Then, i have created the OneToOne relation with the User
entity
New property name (press <return> to stop adding fields):
> user
Field type (enter ? to see all types) [string]:
> relation
What class should this entity be related to?:
> User
Relation type? [ManyToOne, OneToMany, ManyToMany, OneToOne]:
> OneToOne
Is the UserInformation.user property allowed to be null (nullable)? (yes/no) [yes]:
> no
And finally, I added the bio
field into the user_information
Add another property? Enter the property name (or press <return> to stop adding fields):
> bio
Field type (enter ? to see all types) [string]:
>
Field length [255]:
>
Can this field be null in the database (nullable) (yes/no) [no]:
> yes
updated: src/Entity/UserInformation.php
The problem
the problem is that all my user currently have a null
value for the user_information
.
I would like to add an empty user_information for all my user but I have no idea about how to do this.
I know I could write some script to create a user_information
for each user but there might be something else