From e60f172d06acc78801b715deb08e9a8cddc2db4a Mon Sep 17 00:00:00 2001 From: michaelward82 Date: Fri, 11 Apr 2014 14:50:39 +0100 Subject: [PATCH] Resolves issue #88. Allows static calling of Model subclasses, ignoring namespace info during table name generation. Model class static property $_table_use_short_name = true allows static calling of the model subclass whilst avoiding the inclusion of namespace information in the auto generated table name. --- docs/models.rst | 17 ++++++++++++++--- paris.php | 17 ++++++++++++++++- test/ParisTest53.php | 9 +++++++++ 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/docs/models.rst b/docs/models.rst index 2a4d8139..3816f379 100644 --- a/docs/models.rst +++ b/docs/models.rst @@ -37,8 +37,19 @@ in a similar way. For example ``\Models\CarTyre`` would be converted to ``models_car_tyre``. Note here that backslashes are replaced with underscores in addition to the *CapWords* replacement discussed in the previous paragraph. -To override this default behaviour, add a **public static** property to -your class called ``$_table``: +To disregard namespace information when calculating the table name, set a +**public static** property named ``$_table_use_short_name`` on your class. +This would result in ``\Models\CarTyre`` being converted to ``car_tyre``. + +.. code-block:: php + + assertEquals($expected, ORM::get_last_query()); } + public function testIgnoredNamespaceTableName() { + IgnoreNamespace::find_many(); + $expected = 'SELECT * FROM `ignore_namespace`'; + $this->assertEquals($expected, ORM::get_last_query()); + } + public function testModelWithCustomTable() { Model::factory('ModelWithCustomTable')->find_many(); $expected = 'SELECT * FROM `custom_table`'; @@ -43,3 +49,6 @@ class Simple extends Model { } class ModelWithCustomTable extends Model { public static $_table = 'custom_table'; } +class IgnoreNamespace extends Model { + public static $_table_use_short_name = true; +}