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

fixed fetchPage can't set attribute in event #2096

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fanybook
Copy link

@fanybook fanybook commented Dec 24, 2020

  • Related Issues: #IssueNumber if necessary
  • Previous PRs: #PRNumber if this PR is a follow-up

Introduction

when set attribute in event fetched:collection

    this.on('fetched:collection', function(collection, response, options) {
      collection.forEach(model => {
        model.set('abc', 0)
      })
    })

pagination.rowCount is wrong (fetchPage case)

            // ↓↓ the keys is `[ 'count(distinct `test_table`.`id`)', 'abc' ]`
            const keys = Object.keys(result.models[0].attributes);

            // ↓↓ keys.length == 2
            if (keys.length === 1) {
              const key = Object.keys(result.models[0].attributes)[0];
              metadata.rowCount = parseInt(result.models[0].attributes[key]);
            }

Motivation

fix this bug

Proposed solution

            if (keys.length >= 1) {
              const key = keys[0];
              metadata.rowCount = parseInt(result.models[0].attributes[key]);
            }

Current PR Issues

Are there any known issues in this Pull Request? This will help others understand if more work will be needed.

Alternatives considered

Describe any alternative approaches to addressing the same problem that you have thought about, and why you chose this
approach instead.

when
```js
    this.on('fetched:collection', function(collection, response, options) {
      collection.forEach(model => {
        model.set('abc', 0)
      })
    })
```

the keys is `[ 'count(distinct `stock_agu_data`.`id`)', 'abc' ]`,pagination is wrong
Copy link
Member

@ricardograca ricardograca left a comment

Choose a reason for hiding this comment

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

The changes look appropriate but can you fill in the rest of the description template and provide tests for this?

@fanybook
Copy link
Author

@ricardograca
I don't know where to write test code. Can you give me a demonstration? I'm a nodejs newbie,i am phper.

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.

None yet

2 participants