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

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

Closed
sgress454 opened this issue Feb 17, 2017 · 3 comments
Closed

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

sgress454 opened this issue Feb 17, 2017 · 3 comments
Labels

Comments

@sgress454
Copy link
Member

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

@sgress454 sgress454 added the bug label Feb 17, 2017
@sgress454
Copy link
Member Author

From @sailsbot on September 23, 2015 6:53

Thanks for posting, @dmarcelino. I'm a repo bot-- nice to meet you!

It has been 30 days since there have been any updates or new comments on this page. If this issue has been resolved, feel free to disregard the rest of this message. On the other hand, if you are still waiting on a patch, please:

  • review our contribution guide to make sure this submission meets our criteria (only verified bugs with documented features, please; no questions, commentary, or bug reports about undocumented features or unofficial plugins)
  • create a new issue with the latest information, including updated version details with error messages, failing tests, and a link back to the original issue. This allows GitHub to automatically create a back-reference for future visitors arriving from search engines.

Thanks so much for your help!

@sgress454
Copy link
Member Author

Following up on this, I can reproduce using @dmarcelino's test in waterline-adapter-tests, but I can't reproduce it just using a regular Sails app and models in Sails v0.12.x/Waterline v0.11.x/sails-mysql v0.11.x, which is puzzling. With Sails 1.0 and the relevant adapter it seems to work fine. Going to migrate this issue over.

@sgress454
Copy link
Member Author

🎉This was tested as working in the official 1.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

1 participant