diff --git a/unit-tests/ModelsRelationsTest.php b/unit-tests/ModelsRelationsTest.php index b8b054f55d1..daa83035ccf 100644 --- a/unit-tests/ModelsRelationsTest.php +++ b/unit-tests/ModelsRelationsTest.php @@ -34,8 +34,8 @@ public function __destruct() public function modelsAutoloader($className) { $className = str_replace('\\', DIRECTORY_SEPARATOR, $className); - if (file_exists('unit-tests/models/'.$className.'.php')) { - require 'unit-tests/models/'.$className.'.php'; + if (file_exists('unit-tests/models/Relations/' . $className . '.php')) { + require 'unit-tests/models/Relations/' . $className . '.php'; } } diff --git a/unit-tests/models/Relations/Deles.php b/unit-tests/models/Relations/Deles.php new file mode 100644 index 00000000000..1f76c49a841 --- /dev/null +++ b/unit-tests/models/Relations/Deles.php @@ -0,0 +1,33 @@ + 'code', + 'name' => 'theName', + ); + } + + public function initialize() + { + $this->hasMany('code', 'RobottersDeles', 'delesCode', array( + 'foreignKey' => array( + 'message' => 'Deles cannot be deleted because is referenced by a Robotter' + ) + )); + } + +} \ No newline at end of file diff --git a/unit-tests/models/Relations/Parts.php b/unit-tests/models/Relations/Parts.php new file mode 100755 index 00000000000..d34385f4e2e --- /dev/null +++ b/unit-tests/models/Relations/Parts.php @@ -0,0 +1,15 @@ +hasMany('id', 'RobotsParts', 'parts_id', array( + 'foreignKey' => array( + 'message' => 'Parts cannot be deleted because is referenced by a Robot' + ) + )); + } + +} \ No newline at end of file diff --git a/unit-tests/models/Relations/Robots.php b/unit-tests/models/Relations/Robots.php new file mode 100755 index 00000000000..21ad8686cb5 --- /dev/null +++ b/unit-tests/models/Relations/Robots.php @@ -0,0 +1,14 @@ +hasMany('id', 'RobotsParts', 'robots_id', array( + 'foreignKey' => true + )); + $this->hasManyToMany('id', 'RobotsParts', 'robots_id', 'parts_id', 'Parts', 'id'); + } + +} \ No newline at end of file diff --git a/unit-tests/models/Relations/RobotsParts.php b/unit-tests/models/Relations/RobotsParts.php new file mode 100755 index 00000000000..91fc6821e3e --- /dev/null +++ b/unit-tests/models/Relations/RobotsParts.php @@ -0,0 +1,18 @@ +belongsTo('parts_id', 'Parts', 'id', array( + 'foreignKey' => true + )); + $this->belongsTo('robots_id', 'Robots', 'id', array( + 'foreignKey' => array( + 'message' => 'The robot code does not exist' + ) + )); + } + +} \ No newline at end of file diff --git a/unit-tests/models/Relations/Robotters.php b/unit-tests/models/Relations/Robotters.php new file mode 100644 index 00000000000..594127ffe5c --- /dev/null +++ b/unit-tests/models/Relations/Robotters.php @@ -0,0 +1,33 @@ + 'code', + 'name' => 'theName', + 'type' => 'theType', + 'year' => 'theYear' + ); + } + + public function initialize() + { + $this->hasMany('code', 'RobottersDeles', 'robottersCode', array( + 'foreignKey' => true + )); + } + +} \ No newline at end of file diff --git a/unit-tests/models/Relations/RobottersDeles.php b/unit-tests/models/Relations/RobottersDeles.php new file mode 100644 index 00000000000..665881a09b9 --- /dev/null +++ b/unit-tests/models/Relations/RobottersDeles.php @@ -0,0 +1,39 @@ + 'code', + 'robots_id' => 'robottersCode', + 'parts_id' => 'delesCode', + ); + } + + public function initialize() + { + + $this->belongsTo('delesCode', 'Deles', 'code', array( + 'foreignKey' => true + )); + + $this->belongsTo('robottersCode', 'Robotters', 'code', array( + 'foreignKey' => array( + 'message' => 'The robotters code does not exist' + ) + )); + } + +} \ No newline at end of file diff --git a/unit-tests/models/Relations/Some/Deles.php b/unit-tests/models/Relations/Some/Deles.php new file mode 100644 index 00000000000..3deaf11b74b --- /dev/null +++ b/unit-tests/models/Relations/Some/Deles.php @@ -0,0 +1,35 @@ + 'code', + 'name' => 'theName', + ); + } + + public function initialize() + { + $this->hasMany('code', 'Some\RobottersDeles', 'delesCode', array( + 'foreignKey' => array( + 'message' => 'Deles cannot be deleted because is referenced by a Robotter' + ) + )); + } + +} \ No newline at end of file diff --git a/unit-tests/models/Relations/Some/Parts.php b/unit-tests/models/Relations/Some/Parts.php new file mode 100644 index 00000000000..1563e558d6d --- /dev/null +++ b/unit-tests/models/Relations/Some/Parts.php @@ -0,0 +1,22 @@ +hasMany('id', 'RobotsParts', 'parts_id', array( + 'foreignKey' => array( + 'message' => 'Parts cannot be deleted because is referenced by a Robot' + ) + )); + } + +} \ No newline at end of file diff --git a/unit-tests/models/Relations/Some/Products.php b/unit-tests/models/Relations/Some/Products.php new file mode 100644 index 00000000000..a195d6b181b --- /dev/null +++ b/unit-tests/models/Relations/Some/Products.php @@ -0,0 +1,52 @@ + array( + 'id', 'name', 'type', 'price' + ), + MetaData::MODELS_PRIMARY_KEY => array( + 'id' + ), + MetaData::MODELS_NON_PRIMARY_KEY => array( + 'name', 'type', 'price' + ), + MetaData::MODELS_NOT_NULL => array( + 'id', 'name', 'type', 'price' + ), + MetaData::MODELS_DATA_TYPES => array( + 'id' => Column::TYPE_INTEGER, + 'name' => Column::TYPE_VARCHAR, + 'type' => Column::TYPE_VARCHAR, + 'price' => Column::TYPE_INTEGER + ), + MetaData::MODELS_DATA_TYPES_NUMERIC => array( + 'id' => true, + 'price' => true, + ), + MetaData::MODELS_IDENTITY_COLUMN => 'id', + MetaData::MODELS_DATA_TYPES_BIND => array( + 'id' => Column::BIND_PARAM_INT, + 'name' => Column::BIND_PARAM_STR, + 'type' => Column::BIND_PARAM_STR, + 'price' => Column::BIND_PARAM_INT, + ), + MetaData::MODELS_AUTOMATIC_DEFAULT_INSERT => array(), + MetaData::MODELS_AUTOMATIC_DEFAULT_UPDATE => array() + ); + } + +} \ No newline at end of file diff --git a/unit-tests/models/Relations/Some/Robots.php b/unit-tests/models/Relations/Some/Robots.php new file mode 100644 index 00000000000..a747e8c679e --- /dev/null +++ b/unit-tests/models/Relations/Some/Robots.php @@ -0,0 +1,25 @@ +hasMany('id', 'Some\RobotsParts', 'robots_id', array( + 'foreignKey' => true + )); + } + + public function getRobotsParts($arguments=null) + { + return $this->getRelated('Some\RobotsParts', $arguments); + } + +} \ No newline at end of file diff --git a/unit-tests/models/Relations/Some/RobotsParts.php b/unit-tests/models/Relations/Some/RobotsParts.php new file mode 100644 index 00000000000..7e42643d90f --- /dev/null +++ b/unit-tests/models/Relations/Some/RobotsParts.php @@ -0,0 +1,25 @@ +belongsTo('parts_id', 'Parts', 'id', array( + 'foreignKey' => true + )); + $this->belongsTo('robots_id', 'Robots', 'id', array( + 'foreignKey' => array( + 'message' => 'The robot code does not exist' + ) + )); + } + +} \ No newline at end of file diff --git a/unit-tests/models/Relations/Some/Robotters.php b/unit-tests/models/Relations/Some/Robotters.php new file mode 100644 index 00000000000..bb8b12c4195 --- /dev/null +++ b/unit-tests/models/Relations/Some/Robotters.php @@ -0,0 +1,40 @@ + 'code', + 'name' => 'theName', + 'type' => 'theType', + 'year' => 'theYear' + ); + } + + public function initialize() + { + $this->hasMany('code', 'Some\RobottersDeles', 'robottersCode', array( + 'foreignKey' => true + )); + } + + public function getRobottersDeles($arguments=null) + { + return $this->getRelated('Some\RobottersDeles', $arguments); + } + +} \ No newline at end of file diff --git a/unit-tests/models/Relations/Some/RobottersDeles.php b/unit-tests/models/Relations/Some/RobottersDeles.php new file mode 100644 index 00000000000..a619023501f --- /dev/null +++ b/unit-tests/models/Relations/Some/RobottersDeles.php @@ -0,0 +1,41 @@ + 'code', + 'robots_id' => 'robottersCode', + 'parts_id' => 'delesCode', + ); + } + + public function initialize() + { + + $this->belongsTo('delesCode', 'Some\Deles', 'code', array( + 'foreignKey' => true + )); + + $this->belongsTo('robottersCode', 'Some\Robotters', 'code', array( + 'foreignKey' => array( + 'message' => 'The robotters code does not exist' + ) + )); + } + +} \ No newline at end of file diff --git a/unit-tests/models/Robots.php b/unit-tests/models/Robots.php index 21ad8686cb5..0ea97772d23 100755 --- a/unit-tests/models/Robots.php +++ b/unit-tests/models/Robots.php @@ -8,7 +8,6 @@ public function initialize() $this->hasMany('id', 'RobotsParts', 'robots_id', array( 'foreignKey' => true )); - $this->hasManyToMany('id', 'RobotsParts', 'robots_id', 'parts_id', 'Parts', 'id'); } } \ No newline at end of file