Skip to content

Commit

Permalink
create a static query method to get an entity fetcher for the entity
Browse files Browse the repository at this point in the history
  • Loading branch information
tflori committed May 29, 2019
1 parent 1ef1375 commit 819ed07
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ public static function getColumnName($attribute)
->getColumnName(static::class, $attribute, static::$columnPrefix, static::$namingSchemeColumn);
}

/**
* Create an entityFetcher for this entity
*
* @return EntityFetcher
*/
public static function query()
{
return EM::getInstance(static::class)->fetch(static::class);
}

/**
* Get the primary key vars
*
Expand Down
18 changes: 18 additions & 0 deletions tests/Entity/HelperTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace ORM\Test\Entity;

use ORM\EntityManager;
use ORM\Test\Entity\Examples\Article;
use ORM\Test\TestCase;

class HelperTest extends TestCase
{
/** @test */
public function queryReturnsAnEntityFetcher()
{
$fetcher = Article::query();

self::assertEquals(EntityManager::getInstance(Article::class)->fetch(Article::class), $fetcher);
}
}

0 comments on commit 819ed07

Please sign in to comment.