Skip to content

Commit 5b1ec54

Browse files
committed
Fix failing tests
1 parent f92b782 commit 5b1ec54

File tree

31 files changed

+232
-6
lines changed

31 files changed

+232
-6
lines changed

src/generator/default/dbmodel.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,14 @@ public function get<?= $relation->getCamelName() ?>()
144144
<?php endif;?>
145145
}
146146
<?php endforeach; ?>
147-
<?php $i = 1;
148-
foreach ($model->belongsToRelations as $relationName => $relation): ?>
147+
<?php $i = 1; $usedRelationNames = [];
148+
foreach ($model->belongsToRelations as $relationName => $relation): ?><?php $number = in_array($relation->getCamelName(), $usedRelationNames) ? $i : '' ?>
149149

150150
# belongs to relation
151-
public function get<?= $relation->getCamelName() . ($i === 1 ? '' : $i) ?>()
151+
public function get<?= $relation->getCamelName() . ($number) ?>()
152152
{
153153
return $this-><?= $relation->getMethod() ?>(\<?= trim($relationNamespace, '\\') ?>\<?= $relation->getClassName() ?>::class, <?php
154154
echo $relation->linkToString() ?>);
155155
}
156-
<?php $i++; endforeach; ?>
156+
<?php $i++; $usedRelationNames[] = $relation->getCamelName(); endforeach; ?>
157157
}

tests/specs/blog/models/base/Category.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,10 @@ public function getPosts()
3838
{
3939
return $this->hasMany(\app\models\Post::class, ['category_id' => 'id'])->inverseOf('category');
4040
}
41+
42+
# belongs to relation
43+
public function getPost()
44+
{
45+
return $this->hasOne(\app\models\Post::class, ['category_id' => 'id']);
46+
}
4147
}

tests/specs/blog/models/base/Post.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,10 @@ public function getComments()
6161
{
6262
return $this->hasMany(\app\models\Comment::class, ['post_id' => 'uid'])->inverseOf('post');
6363
}
64+
65+
# belongs to relation
66+
public function getComment()
67+
{
68+
return $this->hasOne(\app\models\Comment::class, ['post_id' => 'uid']);
69+
}
6470
}

tests/specs/blog/models/base/User.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,16 @@ public function rules()
4444
'email_unique' => [['email'], 'unique'],
4545
];
4646
}
47+
48+
# belongs to relation
49+
public function getPost()
50+
{
51+
return $this->hasOne(\app\models\Post::class, ['created_by_id' => 'id']);
52+
}
53+
54+
# belongs to relation
55+
public function getComment()
56+
{
57+
return $this->hasOne(\app\models\Comment::class, ['author_id' => 'id']);
58+
}
4759
}

tests/specs/blog_v2/models/base/Category.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,10 @@ public function getPosts()
3838
{
3939
return $this->hasMany(\app\models\Post::class, ['category_id' => 'id'])->inverseOf('category');
4040
}
41+
42+
# belongs to relation
43+
public function getPost()
44+
{
45+
return $this->hasOne(\app\models\Post::class, ['category_id' => 'id']);
46+
}
4147
}

tests/specs/blog_v2/models/base/Post.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,10 @@ public function getTags()
7373
return $this->hasMany(\app\models\Tag::class, ['id' => 'tag_id'])
7474
->viaTable('posts2tags', ['post_id' => 'id']);
7575
}
76+
77+
# belongs to relation
78+
public function getComment()
79+
{
80+
return $this->hasOne(\app\models\Comment::class, ['post_id' => 'id']);
81+
}
7682
}

tests/specs/blog_v2/models/base/User.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,16 @@ public function rules()
4747
'email_unique' => [['email'], 'unique'],
4848
];
4949
}
50+
51+
# belongs to relation
52+
public function getPost()
53+
{
54+
return $this->hasOne(\app\models\Post::class, ['created_by_id' => 'id']);
55+
}
56+
57+
# belongs to relation
58+
public function getComment()
59+
{
60+
return $this->hasOne(\app\models\Comment::class, ['user_id' => 'id']);
61+
}
5062
}

tests/specs/fk_col_name/app/models/base/Delivery.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,10 @@ public function rules()
2727
'title_string' => [['title'], 'string'],
2828
];
2929
}
30+
31+
# belongs to relation
32+
public function getWebhook()
33+
{
34+
return $this->hasOne(\app\models\Webhook::class, ['redelivery_of' => 'id']);
35+
}
3036
}

tests/specs/fk_col_name/app/models/base/User.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,10 @@ public function rules()
2828
'name_string' => [['name'], 'string'],
2929
];
3030
}
31+
32+
# belongs to relation
33+
public function getWebhook()
34+
{
35+
return $this->hasOne(\app\models\Webhook::class, ['user_id' => 'id']);
36+
}
3137
}

tests/specs/fk_col_name_index/app/models/base/Delivery.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,16 @@ public function rules()
2727
'title_string' => [['title'], 'string'],
2828
];
2929
}
30+
31+
# belongs to relation
32+
public function getWebhook()
33+
{
34+
return $this->hasOne(\app\models\Webhook::class, ['redelivery_of' => 'id']);
35+
}
36+
37+
# belongs to relation
38+
public function getWebhook2()
39+
{
40+
return $this->hasOne(\app\models\Webhook::class, ['rd_abc_2' => 'id']);
41+
}
3042
}

tests/specs/fk_col_name_index/app/models/base/User.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,10 @@ public function rules()
2828
'name_string' => [['name'], 'string'],
2929
];
3030
}
31+
32+
# belongs to relation
33+
public function getWebhook()
34+
{
35+
return $this->hasOne(\app\models\Webhook::class, ['user_id' => 'id']);
36+
}
3137
}

tests/specs/issue_fix/159_bug_giiapi_generated_rules_emailid/maria/models/base/Mailing.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,10 @@ public function rules()
3030
'paymentMethodName_string' => [['paymentMethodName'], 'string'],
3131
];
3232
}
33+
34+
# belongs to relation
35+
public function getContact()
36+
{
37+
return $this->hasOne(\app\models\Contact::class, ['mailing_id' => 'id']);
38+
}
3339
}

tests/specs/issue_fix/162_bug_dollarref_with_x_faker/app/models/base/Invoice.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,10 @@ public function rules()
2323
{
2424
return [];
2525
}
26+
27+
# belongs to relation
28+
public function getOrder()
29+
{
30+
return $this->hasOne(\app\models\Order::class, ['invoice_id' => 'id']);
31+
}
2632
}

tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/models/base/Account.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,10 @@ public function rules()
3030
'paymentMethodName_string' => [['paymentMethodName'], 'string'],
3131
];
3232
}
33+
34+
# belongs to relation
35+
public function getContact()
36+
{
37+
return $this->hasOne(\app\models\Contact::class, ['account_id' => 'id']);
38+
}
3339
}

tests/specs/issue_fix/25_generate_inverse_relations/mysql/models/base/User.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,22 @@ public function getAccounts()
3434
{
3535
return $this->hasMany(\app\models\Account::class, ['user_id' => 'id'])->inverseOf('user');
3636
}
37+
38+
# belongs to relation
39+
public function getAccount()
40+
{
41+
return $this->hasOne(\app\models\Account::class, ['user_id' => 'id']);
42+
}
43+
44+
# belongs to relation
45+
public function getAccount2()
46+
{
47+
return $this->hasOne(\app\models\Account::class, ['user2_id' => 'id']);
48+
}
49+
50+
# belongs to relation
51+
public function getAccount3()
52+
{
53+
return $this->hasOne(\app\models\Account::class, ['user3' => 'id']);
54+
}
3755
}

tests/specs/issue_fix/29_extension_fk_column_name_cause_error_in_case_of_column_name_without_underscore/mysql/models/base/User.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,10 @@ public function rules()
2727
'name_string' => [['name'], 'string'],
2828
];
2929
}
30+
31+
# belongs to relation
32+
public function getPost()
33+
{
34+
return $this->hasOne(\app\models\Post::class, ['user' => 'id']);
35+
}
3036
}

tests/specs/issue_fix/52_bug_dependenton_allof_with_x_faker_false/mysql/models/base/Animal.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,10 @@ public function rules()
2727
'name_string' => [['name'], 'string'],
2828
];
2929
}
30+
31+
# belongs to relation
32+
public function getInvoice()
33+
{
34+
return $this->hasOne(\app\models\Invoice::class, ['animal_id' => 'id']);
35+
}
3036
}

tests/specs/issue_fix/52_bug_dependenton_allof_with_x_faker_false/mysql/models/base/Fruit.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,10 @@ public function rules()
2727
'name_string' => [['name'], 'string'],
2828
];
2929
}
30+
31+
# belongs to relation
32+
public function getInvoice()
33+
{
34+
return $this->hasOne(\app\models\Invoice::class, ['fruit_id' => 'id']);
35+
}
3036
}

tests/specs/issue_fix/52_bug_dependenton_allof_with_x_faker_false/mysql/models/base/User.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,16 @@ public function rules()
2727
'name_string' => [['name'], 'string'],
2828
];
2929
}
30+
31+
# belongs to relation
32+
public function getInvoice()
33+
{
34+
return $this->hasOne(\app\models\Invoice::class, ['user_id' => 'id']);
35+
}
36+
37+
# belongs to relation
38+
public function getInvoice2()
39+
{
40+
return $this->hasOne(\app\models\Invoice::class, ['user_2_id' => 'id']);
41+
}
3042
}

tests/specs/issue_fix/88_in_case_of_updating_a_model_generator_creates_redundant_inverse_relations/index.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,3 @@ components:
2929
type: string
3030
address:
3131
$ref: '#/components/schemas/Address'
32-
33-

tests/specs/issue_fix/88_in_case_of_updating_a_model_generator_creates_redundant_inverse_relations/mysql/models/base/Address.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,10 @@ public function rules()
2727
'name_string' => [['name'], 'string'],
2828
];
2929
}
30+
31+
# belongs to relation
32+
public function getHuman()
33+
{
34+
return $this->hasOne(\app\models\Human::class, ['address_id' => 'id']);
35+
}
3036
}

tests/specs/issue_fix/model_name_more_than_once_in_faker_148/app/models/base/Account.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,22 @@ public function rules()
2828
'name_string' => [['name'], 'string', 'max' => 40],
2929
];
3030
}
31+
32+
# belongs to relation
33+
public function getE123()
34+
{
35+
return $this->hasOne(\app\models\E123::class, ['account_id' => 'id']);
36+
}
37+
38+
# belongs to relation
39+
public function getE1232()
40+
{
41+
return $this->hasOne(\app\models\E123::class, ['account_2_id' => 'id']);
42+
}
43+
44+
# belongs to relation
45+
public function getE1233()
46+
{
47+
return $this->hasOne(\app\models\E123::class, ['account_3_id' => 'id']);
48+
}
3149
}

tests/specs/petstore/models/base/Store.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,10 @@ public function rules()
2828
'name_string' => [['name'], 'string'],
2929
];
3030
}
31+
32+
# belongs to relation
33+
public function getPet()
34+
{
35+
return $this->hasOne(\app\models\Pet::class, ['store_id' => 'id']);
36+
}
3137
}

tests/specs/petstore_jsonapi/models/base/Pet.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,10 @@ public function getDuplicates()
6363
{
6464
return $this->hasMany(\app\models\Pet::class, ['tag' => 'tag']);
6565
}
66+
67+
# belongs to relation
68+
public function getPetStatistic()
69+
{
70+
return $this->hasOne(\app\models\PetStatistic::class, ['parentPet_id' => 'id']);
71+
}
6672
}

tests/specs/petstore_namespace/mymodels/base/Store.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,10 @@ public function rules()
2828
'name_string' => [['name'], 'string'],
2929
];
3030
}
31+
32+
# belongs to relation
33+
public function getPet()
34+
{
35+
return $this->hasOne(\app\mymodels\Pet::class, ['store_id' => 'id']);
36+
}
3137
}

tests/specs/relations_in_faker/app/models/base/A123.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,10 @@ public function getB123()
3636
{
3737
return $this->hasOne(\app\models\B123::class, ['id' => 'b123_id']);
3838
}
39+
40+
# belongs to relation
41+
public function getRouting()
42+
{
43+
return $this->hasOne(\app\models\Routing::class, ['a123_id' => 'id']);
44+
}
3945
}

tests/specs/relations_in_faker/app/models/base/Account.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,10 @@ public function rules()
2828
'name_string' => [['name'], 'string', 'max' => 40],
2929
];
3030
}
31+
32+
# belongs to relation
33+
public function getDomain()
34+
{
35+
return $this->hasOne(\app\models\Domain::class, ['account_id' => 'id']);
36+
}
3137
}

tests/specs/relations_in_faker/app/models/base/B123.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,16 @@ public function getC123()
3636
{
3737
return $this->hasOne(\app\models\C123::class, ['id' => 'c123_id']);
3838
}
39+
40+
# belongs to relation
41+
public function getA123()
42+
{
43+
return $this->hasOne(\app\models\A123::class, ['b123_id' => 'id']);
44+
}
45+
46+
# belongs to relation
47+
public function getE123()
48+
{
49+
return $this->hasOne(\app\models\E123::class, ['b123_id' => 'id']);
50+
}
3951
}

tests/specs/relations_in_faker/app/models/base/C123.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,10 @@ public function rules()
2727
'name_string' => [['name'], 'string'],
2828
];
2929
}
30+
31+
# belongs to relation
32+
public function getB123()
33+
{
34+
return $this->hasOne(\app\models\B123::class, ['c123_id' => 'id']);
35+
}
3036
}

tests/specs/relations_in_faker/app/models/base/D123.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,10 @@ public function rules()
2727
'name_string' => [['name'], 'string'],
2828
];
2929
}
30+
31+
# belongs to relation
32+
public function getRouting()
33+
{
34+
return $this->hasOne(\app\models\Routing::class, ['d123_id' => 'id']);
35+
}
3036
}

tests/specs/relations_in_faker/app/models/base/Domain.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,10 @@ public function getRoutings()
4444
{
4545
return $this->hasMany(\app\models\Routing::class, ['domain_id' => 'id'])->inverseOf('domain');
4646
}
47+
48+
# belongs to relation
49+
public function getRouting()
50+
{
51+
return $this->hasOne(\app\models\Routing::class, ['domain_id' => 'id']);
52+
}
4753
}

0 commit comments

Comments
 (0)