|
9 | 9 | use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
10 | 10 | use Illuminate\Database\Eloquent\Relations\HasMany;
|
11 | 11 | use Illuminate\Database\Eloquent\Relations\HasOne;
|
| 12 | +use Illuminate\Database\Eloquent\Relations\MorphOne; |
12 | 13 | use Illuminate\Database\Query\Builder as QueryBuilder;
|
13 | 14 | use LastDragon_ru\LaraASP\GraphQL\Testing\Package\BuilderDataProvider;
|
14 | 15 | use LastDragon_ru\LaraASP\GraphQL\Testing\Package\TestCase;
|
@@ -150,6 +151,7 @@ static function (): EloquentBuilder {
|
150 | 151 | implode('`, `', [
|
151 | 152 | BelongsTo::class,
|
152 | 153 | HasOne::class,
|
| 154 | + MorphOne::class, |
153 | 155 | ]),
|
154 | 156 | )),
|
155 | 157 | static function (): EloquentBuilder {
|
@@ -282,6 +284,63 @@ static function (): EloquentBuilder {
|
282 | 284 | ],
|
283 | 285 | ],
|
284 | 286 | ],
|
| 287 | + 'eloquent: '.MorphOne::class => [ |
| 288 | + [ |
| 289 | + 'sql' => ''. |
| 290 | + 'select'. |
| 291 | + ' "table_a".*,'. |
| 292 | + ' "table_alias_0"."name" as "table_alias_0_name",'. |
| 293 | + ' "table_alias_0"."created_at" as "table_alias_0_created_at",'. |
| 294 | + ' "table_alias_1"."name" as "table_alias_1_name",'. |
| 295 | + ' "table_alias_1"."created_at" as "table_alias_1_created_at" '. |
| 296 | + 'from "table_a" '. |
| 297 | + 'left join (select * from "table_b" where'. |
| 298 | + ' "table_b"."morphable_a_id" = ? and "table_b"."morphable_a_id" is not null and'. |
| 299 | + ' "table_b"."morphable_a_type" = ? and "c" = ?'. |
| 300 | + ') as "table_alias_0" on "table_alias_0"."morphable_a_id" = "table_a"."id" '. |
| 301 | + 'left join (select * from "table_c" where'. |
| 302 | + ' "table_c"."morphable_b_id" = ? and "table_c"."morphable_b_id" is not null and'. |
| 303 | + ' "table_c"."morphable_b_type" = ?'. |
| 304 | + ') as "table_alias_1" on "table_alias_1"."morphable_b_id" = "table_alias_0"."id" '. |
| 305 | + 'order by'. |
| 306 | + ' "table_alias_0_name" asc,'. |
| 307 | + ' "table_alias_0_created_at" desc,'. |
| 308 | + ' "table_alias_1_name" desc,'. |
| 309 | + ' "table_alias_1_created_at" desc,'. |
| 310 | + ' "table_a"."name" asc', |
| 311 | + 'bindings' => [ |
| 312 | + 12, |
| 313 | + SortBuilderTest__ModelA::class, |
| 314 | + 'c', |
| 315 | + 56, |
| 316 | + SortBuilderTest__ModelB::class, |
| 317 | + ], |
| 318 | + ], |
| 319 | + static function (): EloquentBuilder { |
| 320 | + return SortBuilderTest__ModelA::query(); |
| 321 | + }, |
| 322 | + [ |
| 323 | + [ |
| 324 | + 'morphOneB' => ['name' => 'asc'], |
| 325 | + ], |
| 326 | + [ |
| 327 | + 'morphOneB' => ['created_at' => 'desc'], |
| 328 | + ], |
| 329 | + [ |
| 330 | + 'morphOneB' => [ |
| 331 | + 'morphOneC' => ['name' => 'desc'], |
| 332 | + ], |
| 333 | + ], |
| 334 | + [ |
| 335 | + 'morphOneB' => [ |
| 336 | + 'morphOneC' => ['created_at' => 'desc'], |
| 337 | + ], |
| 338 | + ], |
| 339 | + [ |
| 340 | + 'name' => 'asc', |
| 341 | + ], |
| 342 | + ], |
| 343 | + ], |
285 | 344 | ];
|
286 | 345 | }
|
287 | 346 | // </editor-fold>
|
@@ -322,6 +381,12 @@ public function hasOneB(): HasOne {
|
322 | 381 | ->where('b', '=', 'b');
|
323 | 382 | }
|
324 | 383 |
|
| 384 | + public function morphOneB(): MorphOne { |
| 385 | + return $this |
| 386 | + ->morphOne(SortBuilderTest__ModelB::class, 'morphable_a') |
| 387 | + ->where('c', '=', 'c'); |
| 388 | + } |
| 389 | + |
325 | 390 | public function unsupported(): HasMany {
|
326 | 391 | return $this->hasMany(SortBuilderTest__ModelB::class);
|
327 | 392 | }
|
@@ -354,6 +419,10 @@ public function belongsToC(): BelongsTo {
|
354 | 419 | public function hasOneC(): HasOne {
|
355 | 420 | return $this->hasOne(SortBuilderTest__ModelC::class, 'model_b_id');
|
356 | 421 | }
|
| 422 | + |
| 423 | + public function morphOneC(): MorphOne { |
| 424 | + return $this->morphOne(SortBuilderTest__ModelC::class, 'morphable_b'); |
| 425 | + } |
357 | 426 | }
|
358 | 427 |
|
359 | 428 | /**
|
|
0 commit comments