Skip to content

Commit

Permalink
Renamed foreign_key_col_in_foreign_table => relationship_col_in_forei…
Browse files Browse the repository at this point in the history
…gn_table
  • Loading branch information
rotimi committed Jul 22, 2024
1 parent ada977c commit cc89cbc
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 85 deletions.
6 changes: 3 additions & 3 deletions class-diagram.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 10 additions & 10 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
Expand Down Expand Up @@ -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

Expand All @@ -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'
);
Expand Down Expand Up @@ -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
);
```
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
```
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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 {

Expand Down
18 changes: 9 additions & 9 deletions src/LeanOrm/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/CommonPropertiesAndMethodsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading

0 comments on commit cc89cbc

Please sign in to comment.