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

Bug: When saving collection case-converter plugin transforms field object field values into snake_case #1

Open
relativityboy opened this issue Jul 27, 2019 · 0 comments

Comments

@relativityboy
Copy link

Introduction / Description

When saving a collection of bookshelf objects the case-converter plugin will transform child objects destined for json/jsonb fields from camelCase into snake_case. It does not do this transformation when saving a single item outside a collection. This inconsistency is bad.

Example

The expectation is for the jsonb field user_account.security_access to have its data saved consistently (preferably without alteration of any kind).

Bookshelf definition

bookshelf = Bookshelf(knex)
bookshelf.plugin('processor')
bookshelf.plugin('pagination')
bookshelf.plugin('case-converter')

User = bookshelf.Model.extend({
      tableName: 'user_account',
    })

    Users = bookshelf.Collection.extend({
      model: User
    })

Save operation for a single user

newUser:(props)=>{
      const query = (new bs.User(props))
      return query.save()
}

Save operation for multiple users

newUsers:(newUsers)=>{
  return (new bs.Users(newUsers)).insert()
}

Example new user data structure when saving as a collection (just pluck one from this when saving as single item)

[{
    "nameFirst": "Kriss",
    "nameLast": "Bunderbatch",
    "email": "kb@zoom.com",
    "securityAccess": {
        "groupIds": [1, 8],
        "nodeIds": [7]
    }

}, {
    "nameFirst": "Maximilian",
    "nameLast": "Powerknob",
    "email": "support@zoom.com",
    "securityAccess": {
        "groupIds": [1, 8],
        "nodeIds": [7]
    }
}]

Expected / Actual behavior

In the example above, the json properties nodeIds & groupIds are expected to be stored within the jsonb field as nodeIds groupIds.

Instead, they altered and stored as node_ids & group_ids within the jsonb field when saved from a collection, but not when saved as a single row insert.

@ricardograca ricardograca transferred this issue from bookshelf/bookshelf Aug 27, 2019
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

No branches or pull requests

1 participant