Browse Source

Merge pull request #5316 from dakota/3.0-has-finder

Add a hasFinder method to table object
Mark Story 11 years ago
parent
commit
0e787e9bdf
2 changed files with 26 additions and 0 deletions
  1. 13 0
      src/ORM/Table.php
  2. 13 0
      tests/TestCase/ORM/TableTest.php

+ 13 - 0
src/ORM/Table.php

@@ -1469,6 +1469,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
  *

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

@@ -3732,4 +3732,17 @@ class TableTest extends TestCase {
 		EventManager::instance()->detach($cb, 'Model.initialize');
 	}
 
+/**
+ * Tests the hasFinder method
+ *
+ * @return void
+ */
+	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'));
+	}
 }