I’m not sure of the best way of wording this, so I’ve struggled to find any information online.
As far as I can tell, when related active records are loaded, either eagerly or lazily, the loaded active records don’t store a reference to the active record that loaded them. I’m trying to determine if there’s a clean way to achieve this.
In my scenario, I have:
-
an AR class Report with a HAS_MANY relation ‘reportSheets’.
-
an AR class ReportSheet with a BELONGS_TO relation ‘report’.
I call $report->reportSheets, which performs a query and stores references to the ReportSheet objects in $report.
How can I automatically store a reference to $report in each of these ReportSheet objects? Currently, calling $this->report from a ReportSheet method causes the Report object to be lazily loaded from the database.
Note that this is not a performance issue. I need to use the original Report object as I have already loaded and configured other related classes.