Closed pkimtani closed 6 months ago
I found a way to workaround my problem
I added a few custom functions to my ThemeFactory
:
public function asChild(ThemeFactory $parentTheme = null)
{
return $this->addState(['parent' => $parentTheme ?? ThemeFactory::new()]);
}
public function activeStatus(int $status = 1)
{
return $this->addState(['status' => $status]);
}
And then from my ThemeStory, I use it like:
public function build(): void
{
ThemeFactory::new()
->asChild()
->activeStatus()
->afterPersist(function ($theme) {
ThemeImageFactory::new(['theme' => $theme])->create(); // This is where the magic happens
})
->create();
}
Guess I just needed to think a bit more and read the documentation again and again to find this. 😆
Hello! I recently came across this library and I am now trying it out in my project. I have a use-case for which I couldn't find a way to use the existing documentation to help me and therefore decided to ask here.
I am using version
1.23.x
due to PHP language version restrictions.Consider the following entities:
Theme
:theme.id
asparent
.status
column which stores1 => ACTIVE
and0 => INACTIVE
.ThemeImages
:Theme
referencingtheme.id
astheme
Now I want to generate some dataset with following requirements:
n
(say,5
) parent themes (meaning,theme.parent = 0
)m
(say,8
) children themes with random parent from above withstatus = 1
.1
or0
.x
(say,13
) theme images with random theme id among thechildren
themes with at least 1 child theme havingstatus = 1
I am trying to solve this with using
Story
where I create the dataset something like:When creating theme images (like below) I can filter themes with status 1, but I couldn't find a way to filter children themes (parent is not null)
Could you help me if this is solvable with existing scope of this version of the library or if there's any other better alternative?
Thanks in advance!