Skip to content
This repository was archived by the owner on May 12, 2022. It is now read-only.

Commit 6b76f51

Browse files
author
Nik Barham
committed
Removed "subclass" functionality.
Improved a couple of exception messages. (Hopefully) improved error on invalid join() call.
1 parent b772628 commit 6b76f51

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

src/Automatorm/Exception/Model.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ private function make_message($code, $data)
6767
return 'Property "'.$column.'" represents a list of objects that have a foreign key that refers to this object. To change this, you must update those objects - you cannot alter this relationship from here.';
6868

6969
case 'MODEL_DATA:UNEXPECTED_COLUMN_NAME':
70-
list($column, $value, $model) = $data;
71-
return 'Property "'.$column.'" does not exist in the schema for this object. Please check the $model for this object, ot look at $obj->var_dump()';
70+
list($model, $column, $value) = $data;
71+
return 'Property "'.$column.'" does not exist in the schema for this object ('.$model->table_name.'). Please check the $model for this object, or look at $obj->var_dump()';
7272

7373
case 'MODEL_DATA_UPDATE:PIVOT_INCORRECT_OBJECT_TYPE':
7474
list($value, $table, $pivot) = $data;

src/Automatorm/Orm/Data.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ public function __set($var, $value)
400400
}
401401

402402
// Undefined column
403-
throw new Exception\Model('MODEL_DATA:UNEXPECTED_COLUMN_NAME', array($var, $value, $this->model));
403+
throw new Exception\Model('MODEL_DATA:UNEXPECTED_COLUMN_NAME', array($this->model, $var, $value));
404404
}
405405

406406
public function commit()

src/Automatorm/Orm/Model.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323

2424
class Model implements \JsonSerializable
2525
{
26-
public static $dbconnection = 'default'; // Override database connection associated with this class - for subclasses
27-
public static $tablename; // Override table associated with this class - for subclasses
26+
public static $dbconnection = 'default'; // Override database connection associated with this class
27+
public static $tablename; // Override table associated with this class
2828
protected static $instance; // An internal store of already created objects so that objects for each row only get created once
2929

3030
/* PUBLIC CONSTRUCTION METHODS */
@@ -85,7 +85,7 @@ final public static function factory($where, $class_or_table_name = null, $datab
8585

8686
// Figure out the base class and table we need based on current context
8787
$schema = Schema::get($database);
88-
list($base_class, $table) = $schema->guessContext($class_or_table_name ?: get_called_class());
88+
list($class, $table) = $schema->guessContext($class_or_table_name ?: get_called_class());
8989

9090
// Get data from database
9191
$data = Model::factoryData($where, $table, $database, $options);
@@ -100,9 +100,6 @@ final public static function factory($where, $class_or_table_name = null, $datab
100100
// Database data object unique to this object
101101
$data_obj = Data::make($row, $table, $schema);
102102

103-
// Ask the base_class if there is a subclass we should be using.
104-
$class = call_user_func(array($base_class, '_subclass'), $data_obj);
105-
106103
// Create the object!!
107104
$obj = new $class($data_obj);
108105

@@ -276,7 +273,7 @@ public function __get($var)
276273
public function __call($var, $args)
277274
{
278275
try {
279-
return $this->_data->join($var, $args[0]);
276+
return $this->_data->join($var, (array) $args[0]);
280277
}
281278
catch (Exception\Model $e)
282279
{

0 commit comments

Comments
 (0)