Description
When attempting to use one of the dynamic relationship builder methods, such as $feed->build_post()
or $feed->create_post()
, on a model that contains a high number of child objects (in a has-many style relationship), it was noticed (originally by @brianmuse) that the model building operation could hang for quite a while. Looking into it more, we discovered that a single line of code was causing the hang-up.
See, when one of those dynamic builders are called, the Model's __call()
method is invoked, which when determining the association to build actually ends up calling the problematic magic getter. This single line of interestingly commented code ends up calling the association's getter. Now, this is normally not problematic for "belongs to" or "has one" style relationships, but can very quickly become unwieldy for "has many" relationships that have a medium-to-large number of child entries. At any rate, regardless of number of related rows, the query that's caused in this style of association initialization is unnecessary and quite inefficient.
In my testing, simply removing this line of code (along with another fix that I'll mention in an upcoming report) fixes the long-query bug and seems to still initialize everything correctly. This bit of code seems to be from the original project's commit in 2009, so I'm not sure if this is something that was previously necessary and no longer is or what exactly, but it seems to have little effect other than the unfortunate querying as the model's relationship is properly invoked further down the execution path.