Added further tests, Fixed speed_update issues, improved search result query count

This commit is contained in:
Dan Brown
2015-11-29 17:33:25 +00:00
parent 22f8a408fa
commit 62338e4a8f
12 changed files with 115 additions and 53 deletions

View File

@ -69,19 +69,18 @@ abstract class Entity extends Model
* @param $type
* @return bool
*/
public function isA($type)
public static function isA($type)
{
return $this->getName() === strtolower($type);
return static::getName() === strtolower($type);
}
/**
* Gets the class name.
* @return string
*/
public function getName()
public static function getName()
{
$fullClassName = get_class($this);
return strtolower(array_slice(explode('\\', $fullClassName), -1, 1)[0]);
return strtolower(array_slice(explode('\\', static::class), -1, 1)[0]);
}
/**
@ -102,6 +101,15 @@ abstract class Entity extends Model
foreach ($wheres as $whereTerm) {
$search->where($whereTerm[0], $whereTerm[1], $whereTerm[2]);
}
if (!static::isA('book')) {
$search = $search->with('book');
}
if(static::isA('page')) {
$search = $search->with('chapter');
}
return $search->get();
}