I have two entities that are related to each other as follows
Assignment <= Many to One => Account
In the fields of MySQL table for Assignment, there is a field called `account_id` which contains the `id` of the linked record in the Account table.
With this in mind, is it possible to insert a new Assignment as follows:
If not possible...
The ORM Docs has a section for how to create a relationship between two entities, but it is not clear to me how insert a single new Assignment record with a link to a single existing Account record specified in it.
Would it be:
Thanks in advance for the guidance
Assignment <= Many to One => Account
In the fields of MySQL table for Assignment, there is a field called `account_id` which contains the `id` of the linked record in the Account table.
With this in mind, is it possible to insert a new Assignment as follows:
PHP Code:
$entity = $entityManager->createEntity('Assignment', [
'account' => /* id of Account record */,
/* other data */
], $saveOptions);
The ORM Docs has a section for how to create a relationship between two entities, but it is not clear to me how insert a single new Assignment record with a link to a single existing Account record specified in it.
Would it be:
PHP Code:
$account = $entityManager->getEntityById('Account', /* id of Account record */);
$assignment = $entityManager->createEntity('Assignment', [
/* other data */
]);
$entityManager->getRDBRepository('Assignment')
->getRelation($assignment, 'account')
->relate($account);
Comment