/** * The check for OwnedModel below, is because it is possible that something like Address 'state' would be coming * into this method for retrieval. but depending how things are called, it might need to use the penultimate * relation instead of looking for the attribute on the $model. * @param RedBeanModel $model * @param string $attribute * @param DisplayAttributeForReportForm $displayAttribute * @return mixedg $value * @throws NotSupportedException */ protected function resolveModelAttributeValueForPenultimateRelation(RedBeanModel $model, $attribute, DisplayAttributeForReportForm $displayAttribute) { if ($model->isAttribute($attribute) && !is_subclass_of($displayAttribute->getResolvedAttributeModelClassName(), 'OwnedModel')) { return $model->{$attribute}; } $penultimateRelation = $displayAttribute->getPenultimateRelation(); if (!$model->isAttribute($penultimateRelation)) { //Fallback. For some reason this could in fact reference the original $model attribute, but because it is //not owned, it gets confused. todo: need to investigate this further because this is not proper. if ($model->isAttribute($attribute)) { return $model->{$attribute}; } throw new NotSupportedException(); } return $model->{$penultimateRelation}->{$attribute}; }