Skip to content

sails-mysql v0.11.x passing array as string to afterUpdate #3990

@sgress454

Description

@sgress454

From @dmarcelino on May 16, 2015 12:30

Originally reported in balderdashy/waterline#698: when executing .update() if the record contains an array, this array becomes a string in the afterUpdate values.

A failing test has been added in balderdashy/waterline-adapter-tests#73 and only sails-mysql breaks it, build results in https://travis-ci.org/balderdashy/waterline-adapter-tests/jobs/62815681#L556

Original issue balderdashy/waterline#698 reported by @chadxz:

When I update a record in the database (using 'sails-mysql' adapter), the values passed to the afterUpdate lifecycle callback looks like this:

{ id: '4d094885-7e6f-4454-91f0-6a55e3d1b6eb',
  accountId: 'webhooksControllerTestAccountId',
  appId: 'webhooksControllerTestAppId',
  endpointId: 'updatedEndpointId',
  webhookURL: 'updatedWebhookURL',
  groups: '["updatedGroups"]',
  createdAt: Thu Oct 23 2014 15:34:12 GMT-0500 (CDT),
  updatedAt: Thu Oct 23 2014 15:34:12 GMT-0500 (CDT) }

As you can tell from the model definition below, the groups field is an array. I have checked to ensure that i'm passing it an array when its going in, and reading it back out of the database the value is an array, but the value passed to the afterUpdate is a string

I can probably fix this and issue a PR, but i was wondering where I should start looking for the issue... would the code responsible for serializing arrays to string and back be in waterline or sails-mysql?

model definition:

module.exports = {

    attributes: {
        id: {
            type: 'string',
            primaryKey: true
        },
        accountId: {
            type: 'string',
            required: true
        },
        appId: {
            type: 'string',
            required: true
        },
        endpointId: {
            type: 'string',
            required: true
        },
        webhookURL: {
            type: 'string',
            required: true
        },
        groups: {
            type: 'array',
            defaultsTo: []
        },
        toJSON: function () {
            var obj = this.toObject();
            delete obj.createdAt;
            delete obj.updatedAt;
            return obj;
        }
    }

Copied from original issue: balderdashy/sails-mysql#219

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions