Browse Source

Add a hasFinder method to table object

Walther Lalk 11 years ago
parent
commit
3fc40228c4
2 changed files with 21 additions and 0 deletions
  1. 13 0
      src/ORM/Table.php
  2. 8 0
      tests/TestCase/ORM/TableTest.php

+ 13 - 0
src/ORM/Table.php

@@ -1482,6 +1482,19 @@ class Table implements RepositoryInterface, EventListenerInterface {
 	}
 
 /**
+ * Returns true if the finder exists for the table
+ *
+ * @param string $type name of finder to check
+ *
+ * @return bool
+ */
+	public function hasFinder($type) {
+		$finder = 'find' . $type;
+
+		return method_exists($this, $finder) || ($this->_behaviors && $this->_behaviors->hasFinder($type));
+	}
+
+/**
  * Calls a finder method directly and applies it to the passed query,
  * if no query is passed a new one will be created and returned
  *

+ 8 - 0
tests/TestCase/ORM/TableTest.php

@@ -3732,4 +3732,12 @@ class TableTest extends TestCase {
 		EventManager::instance()->detach($cb, 'Model.initialize');
 	}
 
+	public function testHasFinder() {
+		$table = TableRegistry::get('articles');
+		$table->addBehavior('Sluggable');
+
+		$this->assertTrue($table->hasFinder('list'));
+		$this->assertTrue($table->hasFinder('noSlug'));
+		$this->assertFalse($table->hasFinder('noFind'));
+	}
 }