Skip to content

Conversation

@kjohnson
Copy link
Contributor

@kjohnson kjohnson commented Nov 23, 2024

Related impress-org/givewp#7626

Description

This PR adds deferred resolution to model factory definitions, such as nested model factories, so that defaults can be overridden without instantiating unused model instances.

Affects

Updates src\Models\Factories\ModelFactory::makeInstance() to support resolving attributes that are callable.

Visuals

public function definition(): array
{
    return [
        'title' => __('GiveWP Campaign', 'give'),
        'formId' => DonationForm::factory()->createAndResolveTo('id'),
    ];
}

@kjohnson kjohnson marked this pull request as ready for review December 6, 2024 20:08
Copy link
Contributor

@JasonTheAdams JasonTheAdams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for porting this over, @kjohnson! 💪

I would like @borkweb to approve this as well, as I've already seen this and would like his thoughts if he has any. 😄

Copy link
Member

@borkweb borkweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! I added a small commit with some standards changes to formatting, but otherwise this is 👨‍🍳 💋

I went ahead and updated @unreleased to @since 1.2.3. You can merge this and tag the release 🕺

@kjohnson
Copy link
Contributor Author

@borkweb @JasonTheAdams what is the procedure for merging PR for this repo? The PR is approved - can it be merged?

@JasonTheAdams JasonTheAdams merged commit 2fb4545 into main Feb 27, 2025
1 check passed
@JasonTheAdams JasonTheAdams deleted the feature/factory-deferred-resolution branch February 27, 2025 19:04
@JasonTheAdams
Copy link
Contributor

Thank you for following up on this, @kjohnson! It's a really handy feature and we appreciate your efforts!

@JasonTheAdams
Copy link
Contributor

JasonTheAdams commented Feb 27, 2025

Just released this in 1.2.3: https://github.com/stellarwp/models/releases/tag/1.2.3 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants