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

Add boolean field conversion #9146

Closed
wants to merge 1 commit into from

Conversation

krangadurai
Copy link

@krangadurai krangadurai commented Aug 23, 2024

Description

Purpose: This commit integrates the conversion of specific fields to boolean values in the find method to ensure consistent data representation when returning API data.

MySQL Boolean Representation: In MySQL, boolean fields are typically stored as integers, with 1 representing true and 0 representing false. However, for many API responses, it is preferable to return these fields as actual boolean values (true/false).

Automatic Conversion: The convertBooleanFields method is called after data retrieval and the afterFind event, ensuring that any specified fields are converted from 1/0 to true/false before the data is returned.

API Consistency: This conversion helps maintain consistency in API responses, aligning the data format with common expectations for boolean values in JSON and other data formats, where true and false are native boolean types.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjis
Copy link
Member

kenjis commented Aug 24, 2024

Thank you for sending this PR!

We expect the following in all Pull Requests (PRs).

Important

We expect all code changes or bug-fixes to be accompanied by one or more tests added to our test suite to prove the code works.

If pull requests do not comply with the above, they will likely be closed. Since we are a team of volunteers, we don't have any more time to work on the framework than you do. Please make it as painless for your contributions to be included as possible.

See https://github.com/codeigniter4/CodeIgniter4/blob/develop/contributing/pull_request.md

@kenjis kenjis added the wrong branch PRs sent to wrong branch label Aug 24, 2024
@kenjis
Copy link
Member

kenjis commented Aug 24, 2024

Why don't you use Model Field Casting int-bool ?
Is it something wrong?

@kenjis kenjis added enhancement PRs that improve existing functionalities tests needed Pull requests that need tests docs needed Pull requests needing documentation write-ups and/or revisions. labels Aug 24, 2024
@krangadurai
Copy link
Author

I want to sincerely apologize for any inconvenience I may have caused. I value your time and appreciate your help. I'll do my best to ensure this doesn't happen again.

@kenjis
Copy link
Member

kenjis commented Aug 25, 2024

@krangadurai No problem, but we recommend you read the in-progress User Guide:
https://codeigniter4.github.io/CodeIgniter4/

@kenjis kenjis closed this Aug 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs needed Pull requests needing documentation write-ups and/or revisions. enhancement PRs that improve existing functionalities tests needed Pull requests that need tests wrong branch PRs sent to wrong branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants