Open issakujitsuk opened 5 months ago
Not to worry, your language isn't poor or rude.
First off, disclaimer: I don't have much experience with API resources, so I can't help much.
But here's the PR where we added refresh: https://github.com/knuckleswtf/scribe/pull/753
I don't fully understand, but it looks like there was a good reason. Maybe the refresh
should be before the load
?π€
Hi, @shalvah. Thanks for your reply.
As you guessed, $factory->create()->refresh()->load($relations)
worked fine for me π
The issues fixed in #753 may have been as follows.
Book table:
CREATE TABLE `books` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(255) COLLATE utf8mb4_bin NOT NULL,
`volume` tinyint unsigned NOT NULL DEFAULT '1', -- β volume has default value
`updated_at` datetime NOT NULL,
`created_at` datetime NOT NULL,
PRIMARY KEY (`id`)
)
BookFactory:
public function definition(): array
{
return [
"title" => fake()->sentence(),
// β volume is undefined.
];
}
Creating a model from a factory:
$book = Book::factory()->create();
/*
= App\Models\Book {
title: "Eveniet nihil temporibus aut.",
updated_at: "2024-01-18 00:00:00",
created_at: "2024-01-18 00:00:00",
id: 1,
}
*/
// β volume is missing
$book->refresh();
/*
= App\Models\Book {
id: 1,
title: "Eveniet nihil temporibus aut.",
volume: 1,
updated_at: "2024-01-18 00:00:00",
created_at: "2024-01-18 00:00:00",
}
*/
Scribe version
4.29.0
PHP version
8.2.8
Framework
Laravel
Framework version
10.17.0
Scribe config
What happened?
Thanks for Scribe.
I declared an attribute like this.
Expected (at BookResource):
As is:
I see a problem here. https://github.com/knuckleswtf/scribe/blob/695c2a99a70f8c6c1b0dd3bf34d0d70af5ca44fc/src/Extracting/InstantiatesExampleModels.php#L72
I am able to load nested relations as expected until
$factory->create()->load($relations)
, but thecontacts
relation is lost inrefresh()
.Sorry if my language is poor and rude.
Docs