|
707 | 707 | expect($fetched->id)->toBe($originalId) |
708 | 708 | ->and($fetched->_id)->toBe($originalId); |
709 | 709 |
|
710 | | - // Verify toArray() includes 'id' key |
| 710 | + // Verify toArray() includes 'id' but not '_id' |
711 | 711 | $array = $fetched->toArray(); |
712 | 712 | expect($array)->toHaveKey('id') |
713 | | - ->and($array['id'])->toBe($originalId); |
| 713 | + ->and($array['id'])->toBe($originalId) |
| 714 | + ->and($array)->not->toHaveKey('_id'); |
714 | 715 |
|
715 | | - // Both 'id' and '_id' should be present for backwards compatibility |
716 | | - expect($array)->toHaveKey('_id') |
717 | | - ->and($array['_id'])->toBe($originalId); |
718 | | - |
719 | | - // Verify toJson() includes 'id' key |
| 716 | + // Verify toJson() includes 'id' but not '_id' |
720 | 717 | $json = json_decode($fetched->toJson(), true); |
721 | 718 | expect($json)->toHaveKey('id') |
722 | | - ->and($json['id'])->toBe($originalId); |
| 719 | + ->and($json['id'])->toBe($originalId) |
| 720 | + ->and($json)->not->toHaveKey('_id'); |
723 | 721 |
|
724 | 722 | // Verify collection serialization also includes 'id' |
725 | 723 | $users = User::where('name', 'John Doe')->get(); |
726 | 724 | $collectionArray = $users->toArray(); |
727 | 725 | expect($collectionArray[0])->toHaveKey('id') |
728 | | - ->and($collectionArray[0]['id'])->toBe($originalId); |
| 726 | + ->and($collectionArray[0]['id'])->toBe($originalId) |
| 727 | + ->and($collectionArray[0])->not->toHaveKey('_id'); |
729 | 728 | }); |
730 | 729 |
|
731 | 730 | it('tests _id is still accessible for backwards compatibility', function () { |
|
0 commit comments