MetaModels\Factory::byTableName PHP Method

byTableName() public static method

Create a MetaModel instance from the table name.
Deprecation: To create an instance use method getMetaModel().
public static byTableName ( string $strTableName ) : metamodels\IMetaModel
$strTableName string The name of the table.
return metamodels\IMetaModel the instance of the MetaModel or null if not found.
    public static function byTableName($strTableName)
    {
        trigger_error('MetaModels\\Factory::byTableName is deprecated and will get removed. ' . 'Use method MetaModels\\Factory::getMetaModel() instead.', E_USER_DEPRECATED);
        $factory = static::getDefaultFactory();
        return $factory->getMetaModel($strTableName);
    }

Usage Example

 /**
  * Test destruction of the auxiliary data.
  *
  * @return void
  */
 public function testDestroyAUX()
 {
     // This marks the test skipped upon error as Contao related testing is not available.
     if (!$this->prepareDb()) {
         return;
     }
     $metamodel = Factory::byTableName('mm_movies');
     /** @var Rating $rating */
     $rating = $metamodel->getAttribute('rating');
     $rating->destroyAUX();
     $query1 = \Database::getInstance()->execute('SELECT * FROM tl_metamodel_rating WHERE mid=1 AND aid=1');
     $this->assertEquals(0, $query1->numRows);
     $this->assertEquals(array(), $query1->fetchAllAssoc());
     // Ensure the data from the other attribute is still present.
     $query2 = \Database::getInstance()->execute('SELECT * FROM tl_metamodel_rating WHERE mid=1 AND aid=2');
     $this->assertEquals(1, $query2->numRows);
     $this->assertEquals(array(array('id' => 2, 'mid' => 1, 'aid' => 2, 'iid' => 1, 'votecount' => 1, 'meanvalue' => 1.0)), $query2->fetchAllAssoc());
 }