Version 5.7
I'm fairly sure this is something to do with lazy loading child beans. But I wanted to see if there is a more detailed explanation for this. Take this code, dispensing two beans and assigning one to a field for the other. Then later I am doing a check for data in a field within the child bean:
```
$importer = R::
findOne('importer', 'id = ?', [$importerId]);
$importer->myfield = 'foo';
R::
store($importer);
$importerLog = R::
findOrDispense('importerlog', 'id = ?', [$importerLogId]);
$importerLog =
reset($importerLog);
$importerLog->importer = $importer;
R::
store($importerLog);
$data = $importerLog->importer->myfield ?? 'empty';
```
In the above case, $data on the last line is always 'empty'. However, if I remove the null coalesce check, it is always 'foo' (as set above it).
I also found that if I reference $importerLog->importer just before that line in any way (even a manual debug evaluation), even the null coalesce works as expected. Which is what led me to believe lazy loading is the culprit and the comparison is being made before Redbean loads the child bean.
Any further detail on this? Better patterns to use? As it stands it seems we shouldn't check the value of a child bean field before it's loaded into a variable or used in another way?
Cheers
Aaron