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
}

0 commit comments

Comments
 (0)