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

Accept an option 'default' to allow setting default serialized value for association if null #78

Merged

Conversation

vinaya-procore
Copy link
Contributor

Included in the PR

For models that have belongs_to association that allow null relationship, blueprinter serializes to null by default. This PR adds an ability to add a default option to blueprinter association which can be used as the serialized value instead of null.

In cases when the association company is nil, the behavior looks as follows:

Before

class UserBlueprint < Blueprinter::Base
    identifier :uuid
    association :company, blueprint: CompanyBlueprint
end

UserBlueprint.render(user) renders { "id": 1, "company": null }

After

class UserBlueprint < Blueprinter::Base
    identifier :uuid
    association :company, blueprint: CompanyBlueprint, default: {}
end

UserBlueprint.render(user) renders { "id": 1, "company": {} }

Copy link
Contributor

@philipqnguyen philipqnguyen left a comment

Choose a reason for hiding this comment

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

Looks good to me! Since it's a new feature, would you also bump version.rb to 0.5.0 and update the changelog.md as well?

@philipqnguyen philipqnguyen merged commit 1c9a568 into procore-oss:master May 15, 2018
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.

5 participants