Skip to content
This repository
Browse code

API DataObject#relField now checks for method on model before property

  • Loading branch information...
commit 367c49d6b1b39dc9929a9de8cd8888d516b4db22 1 parent 15e2efb
Hamish Friedlander authored July 27, 2012

Showing 1 changed file with 8 additions and 8 deletions. Show diff stats Hide diff stats

  1. 16  model/DataObject.php
16  model/DataObject.php
@@ -2514,13 +2514,14 @@ public function relObject($fieldPath) {
2514 2514
 	 * @param $fieldPath string
2515 2515
 	 * @return string
2516 2516
 	 */
2517  
-	public function relField($fieldPath) {
2518  
-		if(strpos($fieldPath, '.') !== false) {
2519  
-			$parts = explode('.', $fieldPath);
  2517
+	public function relField($fieldName) {
  2518
+		$component = $this;
  2519
+
  2520
+		if(strpos($fieldName, '.') !== false) {
  2521
+			$parts = explode('.', $fieldName);
2520 2522
 			$fieldName = array_pop($parts);
2521 2523
 
2522 2524
 			// Traverse dot syntax
2523  
-			$component = $this;
2524 2525
 			foreach($parts as $relation) {
2525 2526
 				if($component instanceof SS_List) {
2526 2527
 					if(method_exists($component,$relation)) $component = $component->$relation();
@@ -2529,11 +2530,10 @@ public function relField($fieldPath) {
2529 2530
 					$component = $component->$relation();
2530 2531
 				}
2531 2532
 			}
2532  
-
2533  
-			return $component->$fieldName;
2534  
-		} else {
2535  
-			return $this->$fieldPath;
2536 2533
 		}
  2534
+
  2535
+		if ($component->hasMethod($fieldName)) return $component->$fieldName();
  2536
+		return $component->$fieldName;
2537 2537
 	}
2538 2538
 
2539 2539
 	/**

0 notes on commit 367c49d

Please sign in to comment.
Something went wrong with that request. Please try again.