Permalink
Browse files

BUGFIX Versioned_Version->relField() so fields can be used in GridFie…

…ld etc

Copied from DataObject, since we can't use the $fallback opion in this case
(will try to retrieve from wrong class)
  • Loading branch information...
1 parent 703c10a commit f7cd316d1f6e4c92527ce00d71a877db6bac17d7 @chillu chillu committed Jan 14, 2013
Showing with 28 additions and 0 deletions.
  1. +28 −0 model/Versioned.php
View
@@ -1210,4 +1210,32 @@ public function Publisher() {
public function Published() {
return !empty( $this->record['WasPublished'] );
}
+
+ /**
+ * Copied from DataObject to allow access via dot notation.
+ */
+ public function relField($fieldName) {
+ $component = $this;
+
+ if(strpos($fieldName, '.') !== false) {
+ $parts = explode('.', $fieldName);
+ $fieldName = array_pop($parts);
+
+ // Traverse dot syntax
+ foreach($parts as $relation) {
+ if($component instanceof SS_List) {
+ if(method_exists($component,$relation)) $component = $component->$relation();
+ else $component = $component->relation($relation);
+ } else {
+ $component = $component->$relation();
+ }
+ }
+ }
+
+ // Unlike has-one's, these "relations" can return false
+ if($component) {
+ if ($component->hasMethod($fieldName)) return $component->$fieldName();
+ return $component->$fieldName;
+ }
+ }
}

0 comments on commit f7cd316

Please sign in to comment.