diff --git a/class-diagram.svg b/class-diagram.svg index bf6050f..a9faf85 100644 --- a/class-diagram.svg +++ b/class-diagram.svg @@ -2084,7 +2084,7 @@ , foreign_table_name , - foreign_key_col_in_foreign_table + relationship_col_in_foreign_table , primary_key_col_in_foreign_table , @@ -2591,7 +2591,7 @@ , foreign_table_name , - foreign_key_col_in_foreign_table + relationship_col_in_foreign_table , primary_key_col_in_foreign_table , @@ -2663,7 +2663,7 @@ , foreign_table_name , - foreign_key_col_in_foreign_table + relationship_col_in_foreign_table , primary_key_col_in_foreign_table , diff --git a/docs/getting-started.md b/docs/getting-started.md index 04b675a..ab829c8 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -1070,7 +1070,7 @@ $authorsModel = new \LeanOrm\Model( $authorsModel->hasMany( relation_name: 'posts', relationship_col_in_my_table: 'author_id', - foreign_key_col_in_foreign_table: 'author_id', + relationship_col_in_foreign_table: 'author_id', foreign_table_name: 'posts', primary_key_col_in_foreign_table: 'post_id' ); @@ -1113,7 +1113,7 @@ class PostsModel extends \LeanOrm\Model { $authorsModel->hasMany( relation_name: 'posts', relationship_col_in_my_table: 'author_id', - foreign_key_col_in_foreign_table: 'author_id', + relationship_col_in_foreign_table: 'author_id', foreign_models_class_name: PostsModel::class ); // does the same thing as the previous call to hasMany above @@ -1134,7 +1134,7 @@ $postsModel = new \LeanOrm\Model( $postsModel->belongsTo( relation_name: 'author', relationship_col_in_my_table: 'author_id', - foreign_key_col_in_foreign_table: 'author_id', + relationship_col_in_foreign_table: 'author_id', foreign_table_name: 'authors', primary_key_col_in_foreign_table: 'author_id' ); @@ -1178,7 +1178,7 @@ class AuthorsModel extends \LeanOrm\Model { $postsModel->belongsTo( relation_name: 'author', relationship_col_in_my_table: 'author_id', - foreign_key_col_in_foreign_table: 'author_id', + relationship_col_in_foreign_table: 'author_id', foreign_models_class_name: AuthorsModel::class ); ``` @@ -1268,7 +1268,7 @@ $postsModel = new \LeanOrm\Model ( $postsModel->hasOne( relation_name: 'summary', relationship_col_in_my_table: 'post_id', - foreign_key_col_in_foreign_table: 'post_id', + relationship_col_in_foreign_table: 'post_id', foreign_table_name: 'summaries', primary_key_col_in_foreign_table: 'summary_id' ); // Post has one Summary @@ -1312,7 +1312,7 @@ class SummariesModel extends \LeanOrm\Model { $postsModel->hasOne( relation_name: 'summary', relationship_col_in_my_table: 'post_id', - foreign_key_col_in_foreign_table: 'post_id', + relationship_col_in_foreign_table: 'post_id', foreign_models_class_name: SummariesModel::class ); // Post has one Summary ``` @@ -1355,7 +1355,7 @@ class AuthorsModel extends \LeanOrm\Model { $this->hasMany( relation_name: 'posts', relationship_col_in_my_table: 'author_id', - foreign_key_col_in_foreign_table: 'author_id', + relationship_col_in_foreign_table: 'author_id', foreign_models_class_name: PostsModel::class ); // Author has Many Posts } @@ -1385,14 +1385,14 @@ class PostsModel extends \LeanOrm\Model { $this->belongsTo( relation_name: 'author', relationship_col_in_my_table: 'author_id', - foreign_key_col_in_foreign_table: 'author_id', + relationship_col_in_foreign_table: 'author_id', foreign_models_class_name: AuthorsModel::class ); // Post belongs to an Author $this->hasOne( relation_name: 'summary', relationship_col_in_my_table: 'post_id', - foreign_key_col_in_foreign_table: 'post_id', + relationship_col_in_foreign_table: 'post_id', foreign_models_class_name: SummariesModel::class ); // Post has one Summary @@ -1509,7 +1509,7 @@ $authorsModel = new \LeanOrm\Model( $authorsModel->hasMany( relation_name: 'posts', relationship_col_in_my_table: 'author_id', - foreign_key_col_in_foreign_table: 'author_id', + relationship_col_in_foreign_table: 'author_id', foreign_models_class_name: PostsModel::class, sql_query_modifier: function(\Aura\SqlQuery\Common\Select $selectObj): \Aura\SqlQuery\Common\Select { diff --git a/src/LeanOrm/Model.php b/src/LeanOrm/Model.php index 283d29d..4c5ac10 100644 --- a/src/LeanOrm/Model.php +++ b/src/LeanOrm/Model.php @@ -2692,7 +2692,7 @@ public function hasOne( string $relationship_col_in_my_table, - string $foreign_key_col_in_foreign_table, + string $relationship_col_in_foreign_table, string $foreign_table_name='', // If empty, the value set in the $table_name property // of the model class specified in $foreign_models_class_name @@ -2739,14 +2739,14 @@ public function hasOne( $this->validateTableName($foreign_table_name); $this->validateThatTableHasColumn($this->getTableName(), $relationship_col_in_my_table); - $this->validateThatTableHasColumn($foreign_table_name, $foreign_key_col_in_foreign_table); + $this->validateThatTableHasColumn($foreign_table_name, $relationship_col_in_foreign_table); $this->validateThatTableHasColumn($foreign_table_name, $primary_key_col_in_foreign_table); $this->relations[$relation_name] = []; $this->relations[$relation_name]['relation_type'] = \GDAO\Model::RELATION_TYPE_HAS_ONE; $this->relations[$relation_name]['foreign_key_col_in_my_table'] = $relationship_col_in_my_table; $this->relations[$relation_name]['foreign_table'] = $foreign_table_name; - $this->relations[$relation_name]['foreign_key_col_in_foreign_table'] = $foreign_key_col_in_foreign_table; + $this->relations[$relation_name]['foreign_key_col_in_foreign_table'] = $relationship_col_in_foreign_table; $this->relations[$relation_name]['primary_key_col_in_foreign_table'] = $primary_key_col_in_foreign_table; $this->relations[$relation_name]['foreign_models_class_name'] = $foreign_models_class_name; @@ -2770,7 +2770,7 @@ public function belongsTo( string $relationship_col_in_my_table, - string $foreign_key_col_in_foreign_table, + string $relationship_col_in_foreign_table, string $foreign_table_name = '', // If empty, the value set in the $table_name property // of the model class specified in $foreign_models_class_name @@ -2817,14 +2817,14 @@ public function belongsTo( $this->validateTableName($foreign_table_name); $this->validateThatTableHasColumn($this->getTableName(), $relationship_col_in_my_table); - $this->validateThatTableHasColumn($foreign_table_name, $foreign_key_col_in_foreign_table); + $this->validateThatTableHasColumn($foreign_table_name, $relationship_col_in_foreign_table); $this->validateThatTableHasColumn($foreign_table_name, $primary_key_col_in_foreign_table); $this->relations[$relation_name] = []; $this->relations[$relation_name]['relation_type'] = \GDAO\Model::RELATION_TYPE_BELONGS_TO; $this->relations[$relation_name]['foreign_key_col_in_my_table'] = $relationship_col_in_my_table; $this->relations[$relation_name]['foreign_table'] = $foreign_table_name; - $this->relations[$relation_name]['foreign_key_col_in_foreign_table'] = $foreign_key_col_in_foreign_table; + $this->relations[$relation_name]['foreign_key_col_in_foreign_table'] = $relationship_col_in_foreign_table; $this->relations[$relation_name]['primary_key_col_in_foreign_table'] = $primary_key_col_in_foreign_table; $this->relations[$relation_name]['foreign_models_class_name'] = $foreign_models_class_name; @@ -2849,7 +2849,7 @@ public function hasMany( string $relationship_col_in_my_table, - string $foreign_key_col_in_foreign_table, + string $relationship_col_in_foreign_table, string $foreign_table_name='', // If empty, the value set in the $table_name property // of the model class specified in $foreign_models_class_name @@ -2897,14 +2897,14 @@ public function hasMany( $this->validateTableName($foreign_table_name); $this->validateThatTableHasColumn($this->getTableName(), $relationship_col_in_my_table); - $this->validateThatTableHasColumn($foreign_table_name, $foreign_key_col_in_foreign_table); + $this->validateThatTableHasColumn($foreign_table_name, $relationship_col_in_foreign_table); $this->validateThatTableHasColumn($foreign_table_name, $primary_key_col_in_foreign_table); $this->relations[$relation_name] = []; $this->relations[$relation_name]['relation_type'] = \GDAO\Model::RELATION_TYPE_HAS_MANY; $this->relations[$relation_name]['foreign_key_col_in_my_table'] = $relationship_col_in_my_table; $this->relations[$relation_name]['foreign_table'] = $foreign_table_name; - $this->relations[$relation_name]['foreign_key_col_in_foreign_table'] = $foreign_key_col_in_foreign_table; + $this->relations[$relation_name]['foreign_key_col_in_foreign_table'] = $relationship_col_in_foreign_table; $this->relations[$relation_name]['primary_key_col_in_foreign_table'] = $primary_key_col_in_foreign_table; $this->relations[$relation_name]['foreign_models_class_name'] = $foreign_models_class_name; diff --git a/tests/CommonPropertiesAndMethodsTrait.php b/tests/CommonPropertiesAndMethodsTrait.php index 480cc93..0776058 100644 --- a/tests/CommonPropertiesAndMethodsTrait.php +++ b/tests/CommonPropertiesAndMethodsTrait.php @@ -247,7 +247,7 @@ protected function setUp(): void { relation_name: 'posts', relationship_col_in_my_table: 'author_id', foreign_table_name: 'posts', - foreign_key_col_in_foreign_table: 'author_id', + relationship_col_in_foreign_table: 'author_id', primary_key_col_in_foreign_table: 'post_id', foreign_models_class_name: \ModelForTestingPublicAndProtectedMethods::class, foreign_models_record_class_name: \RecordForTestingPublicAndProtectedMethods::class, diff --git a/tests/ModelTest.php b/tests/ModelTest.php index cd2102c..167a7e7 100644 --- a/tests/ModelTest.php +++ b/tests/ModelTest.php @@ -165,7 +165,7 @@ public function testThatBelongsToThrowsExceptionWhenRelationNameCollidesWithColu relation_name: 'author_id', relationship_col_in_my_table: '', foreign_table_name: '', - foreign_key_col_in_foreign_table: '', + relationship_col_in_foreign_table: '', primary_key_col_in_foreign_table: '' ); } @@ -180,7 +180,7 @@ public function testThatBelongsToThrowsExceptionWithInvalidForeignModelClassName relation_name: 'post', relationship_col_in_my_table: 'post_id', foreign_table_name: 'posts', - foreign_key_col_in_foreign_table: 'post_id', + relationship_col_in_foreign_table: 'post_id', primary_key_col_in_foreign_table: 'post_id', foreign_models_class_name: \PDO::class, // bad Model class name foreign_models_record_class_name: LeanOrm\TestObjects\PostRecord::class, @@ -198,7 +198,7 @@ public function testThatBelongsToThrowsExceptionWithInvalidForeignRecordClassNam relation_name: 'post', relationship_col_in_my_table: 'post_id', foreign_table_name: 'posts', - foreign_key_col_in_foreign_table: 'post_id', + relationship_col_in_foreign_table: 'post_id', primary_key_col_in_foreign_table: 'post_id', foreign_models_class_name: \LeanOrm\TestObjects\PostsModel::class, foreign_models_record_class_name: \PDO::class, // bad Record class name @@ -216,7 +216,7 @@ public function testThatBelongsToThrowsExceptionWithInvalidForeignCollectionClas relation_name: 'post', relationship_col_in_my_table: 'post_id', foreign_table_name: 'posts', - foreign_key_col_in_foreign_table: 'post_id', + relationship_col_in_foreign_table: 'post_id', primary_key_col_in_foreign_table: 'post_id', foreign_models_class_name: \LeanOrm\TestObjects\PostsModel::class, foreign_models_record_class_name: \LeanOrm\TestObjects\PostRecord::class, @@ -233,7 +233,7 @@ public function testThatBelongsToThrowsExceptionWithNonExistentForeignTableName( relation_name: 'post', relationship_col_in_my_table: 'post_id', foreign_table_name: 'non_existent_foreign_table', // Non-existent foreign table - foreign_key_col_in_foreign_table: 'post_id', + relationship_col_in_foreign_table: 'post_id', primary_key_col_in_foreign_table: 'post_id' ); } @@ -248,7 +248,7 @@ public function testThatBelongsToThrowsExceptionWithNonExistentCol1() { relation_name: 'post', relationship_col_in_my_table: 'non_existent', foreign_table_name: 'posts', - foreign_key_col_in_foreign_table: 'post_id', + relationship_col_in_foreign_table: 'post_id', primary_key_col_in_foreign_table: 'post_id' ); } @@ -264,7 +264,7 @@ public function testThatBelongsToThrowsExceptionWithNonExistentCol2() { relation_name: 'post', relationship_col_in_my_table: 'post_id', foreign_table_name: 'posts', - foreign_key_col_in_foreign_table: 'non_existent', + relationship_col_in_foreign_table: 'non_existent', primary_key_col_in_foreign_table: 'post_id' ); } @@ -280,7 +280,7 @@ public function testThatBelongsToThrowsExceptionWithNonExistentCol3() { relation_name: 'post', relationship_col_in_my_table: 'post_id', foreign_table_name: 'posts', - foreign_key_col_in_foreign_table: 'post_id', + relationship_col_in_foreign_table: 'post_id', primary_key_col_in_foreign_table: 'non_existent' ); } @@ -298,7 +298,7 @@ public function testThatBelongsToThrowsExceptionWithForeignModelWithoutDefaultTa relation_name: 'comment', relationship_col_in_my_table: 'post_id', foreign_models_class_name: LeanOrm\TestObjects\CommentsModel::class, - foreign_key_col_in_foreign_table: 'post_id' + relationship_col_in_foreign_table: 'post_id' ); } @@ -314,7 +314,7 @@ public function testThatBelongsToThrowsExceptionWithLeanOrmModelAsForeignModelWi $model->belongsTo( relation_name: 'comment', relationship_col_in_my_table: 'post_id', - foreign_key_col_in_foreign_table: 'post_id' + relationship_col_in_foreign_table: 'post_id' ); } @@ -331,7 +331,7 @@ public function testThatBelongsToThrowsExceptionWithForeignModelWithoutDefaultPr relation_name: 'comment', relationship_col_in_my_table: 'post_id', foreign_models_class_name: LeanOrm\TestObjects\CommentsModel::class, - foreign_key_col_in_foreign_table: 'post_id', + relationship_col_in_foreign_table: 'post_id', foreign_table_name: 'comments' ); } @@ -348,7 +348,7 @@ public function testThatBelongsToThrowsExceptionWithLeanOrmModelAsForeignModelWi $model->belongsTo( relation_name: 'comment', relationship_col_in_my_table: 'post_id', - foreign_key_col_in_foreign_table: 'post_id', + relationship_col_in_foreign_table: 'post_id', foreign_table_name: 'comments' ); } @@ -360,7 +360,7 @@ public function testThatBelongsToWorksAsExpected() { relation_name: 'author', relationship_col_in_my_table: 'author_id', foreign_table_name: 'authors', - foreign_key_col_in_foreign_table: 'author_id', + relationship_col_in_foreign_table: 'author_id', primary_key_col_in_foreign_table: 'author_id', foreign_models_class_name: $this->modelClass, foreign_models_record_class_name: \LeanOrm\Model\Record::class, @@ -396,7 +396,7 @@ public function testThatBelongsToWorksAsExpected() { relation_name: 'author2', relationship_col_in_my_table: 'author_id', foreign_table_name: 'authors', - foreign_key_col_in_foreign_table: 'author_id', + relationship_col_in_foreign_table: 'author_id', primary_key_col_in_foreign_table: 'author_id', foreign_models_class_name: $this->modelClass, foreign_models_record_class_name: \LeanOrm\TestObjects\PostRecord::class, @@ -415,7 +415,7 @@ public function testThatBelongsToWorksAsExpected() { relation_name: 'comments2', relationship_col_in_my_table: 'post_id', foreign_models_class_name: LeanOrm\TestObjects\CommentsModel2::class, - foreign_key_col_in_foreign_table: 'post_id' + relationship_col_in_foreign_table: 'post_id' ); self::assertEquals(['author', 'author2', 'comments2'], $postsModel->getRelationNames()); $relations = $postsModel->getRelations(); @@ -444,7 +444,7 @@ public function testThatBelongsToWorksAsExpected() { $postsModel->belongsTo( relation_name: 'comments3', relationship_col_in_my_table: 'post_id', - foreign_key_col_in_foreign_table: 'post_id', + relationship_col_in_foreign_table: 'post_id', foreign_table_name: 'comments', primary_key_col_in_foreign_table: 'comment_id' ); @@ -483,7 +483,7 @@ public function testThatHasOneThrowsExceptionWhenRelationNameCollidesWithColumnN relation_name: 'author_id', relationship_col_in_my_table: '', foreign_table_name: '', - foreign_key_col_in_foreign_table: '', + relationship_col_in_foreign_table: '', primary_key_col_in_foreign_table: '' ); } @@ -497,7 +497,7 @@ public function testThatHasOneThrowsExceptionWithInvalidForeignModelClassName() relation_name: 'post', relationship_col_in_my_table: 'post_id', foreign_table_name: 'posts', - foreign_key_col_in_foreign_table: 'post_id', + relationship_col_in_foreign_table: 'post_id', primary_key_col_in_foreign_table: 'post_id', foreign_models_class_name: \PDO::class, // bad Model class name foreign_models_record_class_name: LeanOrm\TestObjects\PostRecord::class, @@ -514,7 +514,7 @@ public function testThatHasOneThrowsExceptionWithInvalidForeignRecordClassName() relation_name: 'post', relationship_col_in_my_table: 'post_id', foreign_table_name: 'posts', - foreign_key_col_in_foreign_table: 'post_id', + relationship_col_in_foreign_table: 'post_id', primary_key_col_in_foreign_table: 'post_id', foreign_models_class_name: \LeanOrm\TestObjects\PostsModel::class, foreign_models_record_class_name: \PDO::class, // bad Record class name @@ -531,7 +531,7 @@ public function testThatHasOneThrowsExceptionWithNonExistentForeignTableName() { relation_name: 'post', relationship_col_in_my_table: 'post_id', foreign_table_name: 'non_existent_foreign_table', // Non-existent foreign table - foreign_key_col_in_foreign_table: 'post_id', + relationship_col_in_foreign_table: 'post_id', primary_key_col_in_foreign_table: 'post_id' ); } @@ -545,7 +545,7 @@ public function testThatHasOneThrowsExceptionWithInvalidForeignCollectionClassNa relation_name: 'post', relationship_col_in_my_table: 'post_id', foreign_table_name: 'posts', - foreign_key_col_in_foreign_table: 'post_id', + relationship_col_in_foreign_table: 'post_id', primary_key_col_in_foreign_table: 'post_id', foreign_models_class_name: \LeanOrm\TestObjects\PostsModel::class, foreign_models_record_class_name: \LeanOrm\TestObjects\PostRecord::class, @@ -562,7 +562,7 @@ public function testThatHasOneThrowsExceptionWithNonExistentCol1() { relation_name: 'post', relationship_col_in_my_table: 'non_existent', foreign_table_name: 'posts', - foreign_key_col_in_foreign_table: 'post_id', + relationship_col_in_foreign_table: 'post_id', primary_key_col_in_foreign_table: 'post_id' ); } @@ -576,7 +576,7 @@ public function testThatHasOneThrowsExceptionWithNonExistentCol2() { relation_name: 'post', relationship_col_in_my_table: 'post_id', foreign_table_name: 'posts', - foreign_key_col_in_foreign_table: 'non_existent', + relationship_col_in_foreign_table: 'non_existent', primary_key_col_in_foreign_table: 'post_id' ); } @@ -590,7 +590,7 @@ public function testThatHasOneThrowsExceptionWithNonExistentCol3() { relation_name: 'post', relationship_col_in_my_table: 'post_id', foreign_table_name: 'posts', - foreign_key_col_in_foreign_table: 'post_id', + relationship_col_in_foreign_table: 'post_id', primary_key_col_in_foreign_table: 'non_existent' ); } @@ -608,7 +608,7 @@ public function testThatHasOneThrowsExceptionWithForeignModelWithoutDefaultTable relation_name: 'comment', relationship_col_in_my_table: 'post_id', foreign_models_class_name: LeanOrm\TestObjects\CommentsModel::class, - foreign_key_col_in_foreign_table: 'post_id' + relationship_col_in_foreign_table: 'post_id' ); } @@ -624,7 +624,7 @@ public function testThatHasOneThrowsExceptionWithLeanOrmModelAsForeignModelWitho $model->hasOne( relation_name: 'comment', relationship_col_in_my_table: 'post_id', - foreign_key_col_in_foreign_table: 'post_id' + relationship_col_in_foreign_table: 'post_id' ); } @@ -641,7 +641,7 @@ public function testThatHasOneThrowsExceptionWithForeignModelWithoutDefaultPrima relation_name: 'comment', relationship_col_in_my_table: 'post_id', foreign_models_class_name: LeanOrm\TestObjects\CommentsModel::class, - foreign_key_col_in_foreign_table: 'post_id', + relationship_col_in_foreign_table: 'post_id', foreign_table_name: 'comments' ); } @@ -658,7 +658,7 @@ public function testThatHasOneThrowsExceptionWithLeanOrmModelAsForeignModelWitho $model->hasOne( relation_name: 'comment', relationship_col_in_my_table: 'post_id', - foreign_key_col_in_foreign_table: 'post_id', + relationship_col_in_foreign_table: 'post_id', foreign_table_name: 'comments' ); } @@ -670,7 +670,7 @@ public function testThatHasOneWorksAsExpected() { relation_name: 'author', relationship_col_in_my_table: 'author_id', foreign_table_name: 'authors', - foreign_key_col_in_foreign_table: 'author_id', + relationship_col_in_foreign_table: 'author_id', primary_key_col_in_foreign_table: 'author_id', foreign_models_class_name: $this->modelClass, foreign_models_record_class_name: \LeanOrm\Model\Record::class, @@ -705,7 +705,7 @@ public function testThatHasOneWorksAsExpected() { relation_name: 'author2', relationship_col_in_my_table: 'author_id', foreign_table_name: 'authors', - foreign_key_col_in_foreign_table: 'author_id', + relationship_col_in_foreign_table: 'author_id', primary_key_col_in_foreign_table: 'author_id', foreign_models_class_name: $this->modelClass, foreign_models_record_class_name: \LeanOrm\TestObjects\AuthorRecord::class, @@ -724,7 +724,7 @@ public function testThatHasOneWorksAsExpected() { relation_name: 'comments2', relationship_col_in_my_table: 'post_id', foreign_models_class_name: LeanOrm\TestObjects\CommentsModel2::class, - foreign_key_col_in_foreign_table: 'post_id' + relationship_col_in_foreign_table: 'post_id' ); self::assertEquals(['author', 'author2', 'comments2'], $postsModel->getRelationNames()); $relations = $postsModel->getRelations(); @@ -753,7 +753,7 @@ public function testThatHasOneWorksAsExpected() { $postsModel->hasOne( relation_name: 'comments3', relationship_col_in_my_table: 'post_id', - foreign_key_col_in_foreign_table: 'post_id', + relationship_col_in_foreign_table: 'post_id', foreign_table_name: 'comments', primary_key_col_in_foreign_table: 'comment_id' ); @@ -792,7 +792,7 @@ public function testThatHasManyThrowsExceptionWhenRelationNameCollidesWithColumn relation_name: 'author_id', relationship_col_in_my_table: '', foreign_table_name: '', - foreign_key_col_in_foreign_table: '', + relationship_col_in_foreign_table: '', primary_key_col_in_foreign_table: '' ); } @@ -807,7 +807,7 @@ public function testThatHasManyThrowsExceptionWithInvalidForeignModelClassName() relation_name: 'posts', relationship_col_in_my_table: 'post_id', foreign_table_name: 'posts', - foreign_key_col_in_foreign_table: 'post_id', + relationship_col_in_foreign_table: 'post_id', primary_key_col_in_foreign_table: 'post_id', foreign_models_class_name: \PDO::class, // bad Model class name foreign_models_record_class_name: LeanOrm\TestObjects\PostRecord::class, @@ -824,7 +824,7 @@ public function testThatHasManyThrowsExceptionWithInvalidForeignRecordClassName( relation_name: 'post', relationship_col_in_my_table: 'post_id', foreign_table_name: 'posts', - foreign_key_col_in_foreign_table: 'post_id', + relationship_col_in_foreign_table: 'post_id', primary_key_col_in_foreign_table: 'post_id', foreign_models_class_name: \LeanOrm\TestObjects\PostsModel::class, foreign_models_record_class_name: \PDO::class, // bad Record class name @@ -841,7 +841,7 @@ public function testThatHasManyThrowsExceptionWithNonExistentForeignTableName() relation_name: 'post', relationship_col_in_my_table: 'post_id', foreign_table_name: 'non_existent', // non-existent foreign table - foreign_key_col_in_foreign_table: 'post_id', + relationship_col_in_foreign_table: 'post_id', primary_key_col_in_foreign_table: 'post_id' ); } @@ -855,7 +855,7 @@ public function testThatHasManyThrowsExceptionWithInvalidForeignCollectionClassN relation_name: 'post', relationship_col_in_my_table: 'post_id', foreign_table_name: 'posts', - foreign_key_col_in_foreign_table: 'post_id', + relationship_col_in_foreign_table: 'post_id', primary_key_col_in_foreign_table: 'post_id', foreign_models_class_name: \LeanOrm\TestObjects\PostsModel::class, foreign_models_record_class_name: \LeanOrm\TestObjects\PostRecord::class, @@ -872,7 +872,7 @@ public function testThatHasManyThrowsExceptionWithNonExistentCol1() { relation_name: 'post', relationship_col_in_my_table: 'non_existent', foreign_table_name: 'posts', - foreign_key_col_in_foreign_table: 'post_id', + relationship_col_in_foreign_table: 'post_id', primary_key_col_in_foreign_table: 'post_id' ); } @@ -886,7 +886,7 @@ public function testThatHasManyThrowsExceptionWithNonExistentCol2() { relation_name: 'post', relationship_col_in_my_table: 'post_id', foreign_table_name: 'posts', - foreign_key_col_in_foreign_table: 'non_existent', + relationship_col_in_foreign_table: 'non_existent', primary_key_col_in_foreign_table: 'post_id' ); } @@ -900,7 +900,7 @@ public function testThatHasManyThrowsExceptionWithNonExistentCol3() { relation_name: 'post', relationship_col_in_my_table: 'post_id', foreign_table_name: 'posts', - foreign_key_col_in_foreign_table: 'post_id', + relationship_col_in_foreign_table: 'post_id', primary_key_col_in_foreign_table: 'non_existent' ); } @@ -918,7 +918,7 @@ public function testThatHasManyThrowsExceptionWithForeignModelWithoutDefaultTabl relation_name: 'comments', relationship_col_in_my_table: 'post_id', foreign_models_class_name: LeanOrm\TestObjects\CommentsModel::class, - foreign_key_col_in_foreign_table: 'post_id' + relationship_col_in_foreign_table: 'post_id' ); } @@ -934,7 +934,7 @@ public function testThatHasManyThrowsExceptionWithLeanOrmModelAsForeignModelWith $model->hasMany( relation_name: 'comments', relationship_col_in_my_table: 'post_id', - foreign_key_col_in_foreign_table: 'post_id' + relationship_col_in_foreign_table: 'post_id' ); } @@ -951,7 +951,7 @@ public function testThatHasManyThrowsExceptionWithForeignModelWithoutDefaultPrim relation_name: 'comments', relationship_col_in_my_table: 'post_id', foreign_models_class_name: LeanOrm\TestObjects\CommentsModel::class, - foreign_key_col_in_foreign_table: 'post_id', + relationship_col_in_foreign_table: 'post_id', foreign_table_name: 'comments' ); } @@ -968,7 +968,7 @@ public function testThatHasManyThrowsExceptionWithLeanOrmModelAsForeignModelWith $model->hasMany( relation_name: 'comments', relationship_col_in_my_table: 'post_id', - foreign_key_col_in_foreign_table: 'post_id', + relationship_col_in_foreign_table: 'post_id', foreign_table_name: 'comments' ); } @@ -980,7 +980,7 @@ public function testThatHasManyWorksAsExpected() { relation_name: 'comments', relationship_col_in_my_table: 'post_id', foreign_table_name: 'comments', - foreign_key_col_in_foreign_table: 'post_id', + relationship_col_in_foreign_table: 'post_id', primary_key_col_in_foreign_table: 'comment_id', foreign_models_class_name: LeanOrm\TestObjects\CommentsModel::class, foreign_models_record_class_name: LeanOrm\TestObjects\CommentRecord::class, @@ -1014,7 +1014,7 @@ public function testThatHasManyWorksAsExpected() { relation_name: 'comments2', relationship_col_in_my_table: 'post_id', foreign_table_name: 'comments', - foreign_key_col_in_foreign_table: 'post_id', + relationship_col_in_foreign_table: 'post_id', primary_key_col_in_foreign_table: 'comment_id', foreign_models_class_name: $this->modelClass, foreign_models_record_class_name: \LeanOrm\TestObjects\CommentRecord::class, @@ -1033,7 +1033,7 @@ public function testThatHasManyWorksAsExpected() { relation_name: 'comments2', relationship_col_in_my_table: 'post_id', foreign_models_class_name: LeanOrm\TestObjects\CommentsModel2::class, - foreign_key_col_in_foreign_table: 'post_id' + relationship_col_in_foreign_table: 'post_id' ); self::assertEquals(['comments', 'comments2'], $postsModel->getRelationNames()); $relations = $postsModel->getRelations(); @@ -1062,7 +1062,7 @@ public function testThatHasManyWorksAsExpected() { $postsModel->hasMany( relation_name: 'comments3', relationship_col_in_my_table: 'post_id', - foreign_key_col_in_foreign_table: 'post_id', + relationship_col_in_foreign_table: 'post_id', foreign_table_name: 'comments', primary_key_col_in_foreign_table: 'comment_id' ); diff --git a/tests/TestObjects/BlogModelClasses/AuthorsModel.php b/tests/TestObjects/BlogModelClasses/AuthorsModel.php index 10e1d53..2d742e6 100644 --- a/tests/TestObjects/BlogModelClasses/AuthorsModel.php +++ b/tests/TestObjects/BlogModelClasses/AuthorsModel.php @@ -18,7 +18,7 @@ public function __construct(string $dsn = '', string $username = '', string $pas relation_name: 'posts', relationship_col_in_my_table: 'author_id', foreign_table_name: 'posts', - foreign_key_col_in_foreign_table: 'author_id', + relationship_col_in_foreign_table: 'author_id', primary_key_col_in_foreign_table: 'post_id', foreign_models_class_name: PostsModel::class, foreign_models_record_class_name: PostRecord::class, @@ -29,7 +29,7 @@ public function __construct(string $dsn = '', string $username = '', string $pas relation_name: 'one_post', relationship_col_in_my_table: 'author_id', foreign_table_name: 'posts', - foreign_key_col_in_foreign_table: 'author_id', + relationship_col_in_foreign_table: 'author_id', primary_key_col_in_foreign_table: 'post_id', foreign_models_class_name: PostsModel::class, foreign_models_record_class_name: PostRecord::class, diff --git a/tests/TestObjects/BlogModelClasses/CommentsModel.php b/tests/TestObjects/BlogModelClasses/CommentsModel.php index 4146643..3ff9b15 100644 --- a/tests/TestObjects/BlogModelClasses/CommentsModel.php +++ b/tests/TestObjects/BlogModelClasses/CommentsModel.php @@ -17,7 +17,7 @@ public function __construct(string $dsn = '', string $username = '', string $pas relation_name: 'post', relationship_col_in_my_table: 'post_id', foreign_table_name: 'posts', - foreign_key_col_in_foreign_table: 'post_id', + relationship_col_in_foreign_table: 'post_id', primary_key_col_in_foreign_table: 'post_id', foreign_models_class_name: PostsModel::class, foreign_models_record_class_name: PostRecord::class, diff --git a/tests/TestObjects/BlogModelClasses/PostsModel.php b/tests/TestObjects/BlogModelClasses/PostsModel.php index e5f7213..6f5f6e5 100644 --- a/tests/TestObjects/BlogModelClasses/PostsModel.php +++ b/tests/TestObjects/BlogModelClasses/PostsModel.php @@ -25,7 +25,7 @@ public function __construct( relation_name: 'author', relationship_col_in_my_table: 'author_id', foreign_table_name: 'authors', - foreign_key_col_in_foreign_table: 'author_id', + relationship_col_in_foreign_table: 'author_id', primary_key_col_in_foreign_table: 'author_id', foreign_models_class_name: AuthorsModel::class, foreign_models_record_class_name: AuthorRecord::class, @@ -35,7 +35,7 @@ public function __construct( relation_name: 'author_with_callback', relationship_col_in_my_table: 'author_id', foreign_table_name: 'authors', - foreign_key_col_in_foreign_table: 'author_id', + relationship_col_in_foreign_table: 'author_id', primary_key_col_in_foreign_table: 'author_id', foreign_models_class_name: AuthorsModel::class, foreign_models_record_class_name: \RecordForTestingPublicAndProtectedMethods::class, @@ -51,7 +51,7 @@ public function __construct( relation_name: 'summary', relationship_col_in_my_table: 'post_id', foreign_table_name: 'summaries', - foreign_key_col_in_foreign_table: 'post_id', + relationship_col_in_foreign_table: 'post_id', primary_key_col_in_foreign_table: 'summary_id', foreign_models_class_name: SummariesModel::class, foreign_models_record_class_name: SummaryRecord::class, @@ -61,7 +61,7 @@ public function __construct( relation_name: 'summary_with_callback', relationship_col_in_my_table: 'post_id', foreign_table_name: 'summaries', - foreign_key_col_in_foreign_table: 'post_id', + relationship_col_in_foreign_table: 'post_id', primary_key_col_in_foreign_table: 'summary_id', foreign_models_class_name: SummariesModel::class, foreign_models_record_class_name: \RecordForTestingPublicAndProtectedMethods::class, @@ -77,7 +77,7 @@ public function __construct( relation_name: 'comments', relationship_col_in_my_table: 'post_id', foreign_table_name: 'comments', - foreign_key_col_in_foreign_table: 'post_id', + relationship_col_in_foreign_table: 'post_id', primary_key_col_in_foreign_table: 'comment_id', foreign_models_class_name: CommentsModel::class, foreign_models_record_class_name: CommentRecord::class, @@ -87,7 +87,7 @@ public function __construct( relation_name: 'comments_with_callback', relationship_col_in_my_table: 'post_id', foreign_table_name: 'comments', - foreign_key_col_in_foreign_table: 'post_id', + relationship_col_in_foreign_table: 'post_id', primary_key_col_in_foreign_table: 'comment_id', foreign_models_class_name: CommentsModel::class, foreign_models_record_class_name: \RecordForTestingPublicAndProtectedMethods::class, @@ -103,7 +103,7 @@ public function __construct( relation_name: 'posts_tags', relationship_col_in_my_table: 'post_id', foreign_table_name: 'posts_tags', - foreign_key_col_in_foreign_table: 'post_id', + relationship_col_in_foreign_table: 'post_id', primary_key_col_in_foreign_table: 'posts_tags_id', foreign_models_class_name: PostsTagsModel::class, foreign_models_record_class_name: PostTagRecord::class, diff --git a/tests/TestObjects/BlogModelClasses/PostsTagsModel.php b/tests/TestObjects/BlogModelClasses/PostsTagsModel.php index eb48ace..6f5e3fd 100644 --- a/tests/TestObjects/BlogModelClasses/PostsTagsModel.php +++ b/tests/TestObjects/BlogModelClasses/PostsTagsModel.php @@ -74,7 +74,7 @@ public function __construct(string $dsn = '', string $username = '', string $pas relation_name: 'post', relationship_col_in_my_table: 'post_id', foreign_table_name: 'posts', - foreign_key_col_in_foreign_table: 'post_id', + relationship_col_in_foreign_table: 'post_id', primary_key_col_in_foreign_table: 'post_id', foreign_models_class_name: PostsModel::class, foreign_models_record_class_name: PostRecord::class, @@ -84,7 +84,7 @@ public function __construct(string $dsn = '', string $username = '', string $pas relation_name: 'tag', relationship_col_in_my_table: 'tag_id', foreign_table_name: 'tags', - foreign_key_col_in_foreign_table: 'tag_id', + relationship_col_in_foreign_table: 'tag_id', primary_key_col_in_foreign_table: 'tag_id', foreign_models_class_name: TagsModel::class, foreign_models_record_class_name: TagRecord::class, diff --git a/tests/TestObjects/BlogModelClasses/SummariesModel.php b/tests/TestObjects/BlogModelClasses/SummariesModel.php index f60a432..715f614 100644 --- a/tests/TestObjects/BlogModelClasses/SummariesModel.php +++ b/tests/TestObjects/BlogModelClasses/SummariesModel.php @@ -17,7 +17,7 @@ public function __construct(string $dsn = '', string $username = '', string $pas relation_name: 'post', relationship_col_in_my_table: 'post_id', foreign_table_name: 'posts', - foreign_key_col_in_foreign_table: 'post_id', + relationship_col_in_foreign_table: 'post_id', primary_key_col_in_foreign_table: 'post_id', foreign_models_class_name: PostsModel::class, foreign_models_record_class_name: PostRecord::class, diff --git a/tests/TestObjects/BlogModelClasses/TagsModel.php b/tests/TestObjects/BlogModelClasses/TagsModel.php index 82aa8d8..3497b80 100644 --- a/tests/TestObjects/BlogModelClasses/TagsModel.php +++ b/tests/TestObjects/BlogModelClasses/TagsModel.php @@ -26,7 +26,7 @@ public function __construct(string $dsn = '', string $username = '', string $pas relation_name: 'posts_tags', relationship_col_in_my_table: 'tag_id', foreign_table_name: 'posts_tags', - foreign_key_col_in_foreign_table: 'tag_id', + relationship_col_in_foreign_table: 'tag_id', primary_key_col_in_foreign_table: 'posts_tags_id', foreign_models_class_name: PostsTagsModel::class, foreign_models_record_class_name: PostTagRecord::class,