Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return updated/created/saved model from Future #579

Merged
merged 1 commit into from
Oct 29, 2018

Conversation

zdnk
Copy link

@zdnk zdnk commented Oct 29, 2018

Given this code where Client is Model and struct:

        return try request.fromInput(to: Client.self)
            .save(on: request)
            .map {
                return try Client.Output(
                            id: $0.requireID(),
                            platform: $0.platform,
                            role: $0.role,
                            campaignId: $0.campaignId,
                            lastModifiedAt: $0.lastModifiedAt()
                )
            }
            .encode(status: .created, for: request)

The code will fail on requireID() because current implementation of Future.save(on:) returns the model that was passed to it, meaning the ID is still nil.

This PR fixes this scenario and return the return value from corresponding CRUD operations on Model like save(on:) etc.

@twof twof requested a review from tanner0101 October 29, 2018 16:02
Copy link
Member

@twof twof left a comment

Choose a reason for hiding this comment

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

Assuming we're cool with potentially source breaking, I'm in favor of this.

@0xTim
Copy link
Member

0xTim commented Oct 29, 2018

This definitely looks like a bug/oversight

@0xTim 0xTim merged commit 8c2d383 into vapor:master Oct 29, 2018
@penny-coin
Copy link

Hey @zdnk, you just merged a pull request, have a coin!

You now have 1 coins.

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