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

Model Doesn't Update After Create #21

Closed
ghempton opened this issue Dec 31, 2011 · 8 comments
Closed

Model Doesn't Update After Create #21

ghempton opened this issue Dec 31, 2011 · 8 comments

Comments

@ghempton
Copy link
Member

App.store.create App.person
    name: "John"

App.store.commit()

# Adapter saves data to server. Server returns newly created object that includes the id field. Adapter calls the didCreateModel method on the store.

{{#view App.PersonView contentBinding="this"}}
   {{#with content}}
     {{id}}
   {{/with}}
{{/view}}

The above view never updates with the correct id returned from the server.

@wycats
Copy link
Member

wycats commented Dec 31, 2011

Can I see your adapter?

@wycats
Copy link
Member

wycats commented Dec 31, 2011

Ah!

The problem is that you haven't declared id as a DS.attr. As a result, when the data changes, the model is never notified that the id property has changed. If you want to expose attributes from your models that you can observe, you need to do:

App.Person = DS.Model.extend
  id: DS.attr("integer")

@ghempton
Copy link
Member Author

I tried that to no avail. Instead, the binding always shows NaN.

I notice that didCreateModel doesn't have a call to model.set('data', hash); and didCreateModels (plural) does have the call. Despite trying to add it, it still doesn't work.

Here is my store/adapter:

App.store = DS.Store.create
  adapter: DS.Adapter.create
    findAll: (store, type) ->
      url = type.collectionUrl
      $.getJSON url, (data) ->
        store.loadMany type, data
    create: (store, type, model) ->
      url = type.collectionUrl
      $.ajax
        data:
          resource: model.get('data')
        dataType: 'json'
        type: 'POST'
        url: url
        success: (data) ->
          console.log data
          store.didCreateModel model, data
    update: (store, type, model) ->
      url = type.url.fmt(model.get('id'))
      $.ajax
        data:
          resource: model.get('data')
        dataType: 'json'
        type: 'PUT'
        url: url
        success: (data) ->
          store.didUpdateModel model, data
    deleteModel: (store, type, model) ->
      url = type.url.fmt(model.get('id'))
      $.ajax
        data:
          resource: model.get('data')
        dataType: 'json'
        type: 'DELETE'
        url: url
        success: (data) ->
          store.didDeleteModel model

@wycats
Copy link
Member

wycats commented Dec 31, 2011

Hey. We fixed one issue in f548be3.

It seems as though there may have been several interrelated issues. Can you try again with id being a DS.attr and with the updated ember-data?

@ghempton
Copy link
Member Author

I pulled the latest and tried again. Unfortunately the binding shows "NaN" (this bug aside, that seems like a poor default for an attribute). I will dig deeper into this issue early next week when I have more time. Thanks!

Out of curiosity, what is the difference between Ember.set(model, 'data', hash) and model.set('data', hash)?

@wycats
Copy link
Member

wycats commented Dec 31, 2011

Out of curiosity, what is the difference between Ember.set(model, 'data', hash) and model.set('data', hash)?

They are the same, but you can use Ember.set on an object that may be a regular JavaScript object:

foo = {}
Ember.set(foo, 'bar', 1)
foo //=> { bar: 1 }
foo.set('bar', 2) // no method set on foo

This is mostly useful if you want to support regular JavaScript objects in some context. In Ember itself, we virtually always use this to liberally accept more kinds of inputs.

ghempton added a commit to ghempton/data that referenced this issue Jan 3, 2012
…now updated after the store's model array has been updated. Fix for emberjs#21.
@ghempton
Copy link
Member Author

ghempton commented Jan 3, 2012

This turned out to be a another model cache issue in conjunction with a collection view. Sent a pull request with the fix and a test case.

@ghempton
Copy link
Member Author

ghempton commented Jan 4, 2012

Fixed.

@ghempton ghempton closed this as completed Jan 4, 2012
iamdtang referenced this issue in iamdtang/data Nov 6, 2019
# This is the 1st commit message:

WIP Tracerbench Travis setup

# This is the commit message #2:

dont checkin results

# This is the commit message #3:

configure azure job, make first thing for testing

# This is the commit message #4:

config updates

# This is the commit message #5:

Able to get results from Tracerbench

# This is the commit message #6:

redirect for tracerbench

# This is the commit message #7:

Update URLs to include ?tracerbench=true

# This is the commit message #8:

wip

# This is the commit message #9:

moves .server-replay.json to root

# This is the commit message #10:

wip

# This is the commit message #11:

cleanup

# This is the commit message #12:

cleanup

# This is the commit message #13:

cleanup

# This is the commit message #14:

cleanup

# This is the commit message #15:

change command

# This is the commit message #16:

Make process terminate with exit code 0

# This is the commit message #17:

Ignore tracerbench-results files

# This is the commit message #18:

Delete generated JSON file

# This is the commit message #19:

rename directory

# This is the commit message #20:

Bump ember-decorators-polyfill from 1.0.6 to 1.1.0

Bumps [ember-decorators-polyfill](https://github.com/pzuraq/ember-decorators-polyfill) from 1.0.6 to 1.1.0.
- [Release notes](https://github.com/pzuraq/ember-decorators-polyfill/releases)
- [Commits](ember-polyfills/ember-decorators-polyfill@1.0.6...1.1.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
# This is the commit message #21:

Bump @ember/optional-features from 1.0.0 to 1.1.0

Bumps [@ember/optional-features](https://github.com/emberjs/ember-optional-features) from 1.0.0 to 1.1.0.
- [Release notes](https://github.com/emberjs/ember-optional-features/releases)
- [Changelog](https://github.com/emberjs/ember-optional-features/blob/master/CHANGELOG.md)
- [Commits](emberjs/ember-optional-features@v1.0.0...v1.1.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
# This is the commit message #22:

[CHORE] fix Typo (emberjs#6635)

Happen to run into this typo. Been using Ember for years, love your work! Good luck!

Co-authored-by: igorT <terzicigor@gmail.com>
# This is the commit message #23:

Update Changelog for v3.13.0

# This is the commit message #24:

update changelog for v3.13.1

# This is the commit message #25:

[CHORE] adds infra for testing calls to Ember warn|deprecate|assert (emberjs#6626)

* [CHORE] adds infra for testing calls to Ember warn|deprecate|assert

* fix production tests

* address feedback

* feedback on labels

* remove id checks

# This is the commit message #26:

[CHORE] Refactor integration/multiple-stores-test.js in order to remove run loop usage (emberjs#6632)


# This is the commit message #27:

Bump ember-simple-tree from 0.7.0 to 0.7.1

Bumps [ember-simple-tree](https://github.com/btecu/ember-simple-tree) from 0.7.0 to 0.7.1.
- [Release notes](https://github.com/btecu/ember-simple-tree/releases)
- [Commits](btecu/ember-simple-tree@0.7.0...0.7.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
# This is the commit message #28:

Bump ember-decorators-polyfill from 1.1.0 to 1.1.1

Bumps [ember-decorators-polyfill](https://github.com/pzuraq/ember-decorators-polyfill) from 1.1.0 to 1.1.1.
- [Release notes](https://github.com/pzuraq/ember-decorators-polyfill/releases)
- [Commits](ember-polyfills/ember-decorators-polyfill@1.1.0...1.1.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
# This is the commit message #29:

cleanup serializer documentation (emberjs#6575)


# This is the commit message #30:

ISSUE-6012: test: added test for meta property and bug fix. (emberjs#6640)


# This is the commit message #31:

[FEAT links] ensures full links object support for relationships (emberjs#6606)

* [FEAT links] ensures full links object support for relationships

* fix lint

* add feature flags

# This is the commit message #32:

[BUGFIX release] Enable `store.createRecord` in FastBoot (emberjs#6568)

* Add FastBoot test for store.createRecord

Fails at the moment.

* Enable store.createRecord in FastBoot

Changes the V4 UUID generation to leverage `FastBoot.require` when
possible. This currently requires that the host application add the
following to their `package.json`:

```
"fastbootDependencies": [
  "crypto"
]
```

* fix types

# This is the commit message #33:

[CHORE] rename and restructure packages to clarify unpublished/private status

move unpublished packages into directories marked private

move published but private into better naming convention

move unpublished into better naming convention

change -build-infra imports to private-build-infra

larger re-org

# This is the commit message #34:

Bump eslint-config-prettier from 6.4.0 to 6.5.0

Bumps [eslint-config-prettier](https://github.com/prettier/eslint-config-prettier) from 6.4.0 to 6.5.0.
- [Release notes](https://github.com/prettier/eslint-config-prettier/releases)
- [Changelog](https://github.com/prettier/eslint-config-prettier/blob/master/CHANGELOG.md)
- [Commits](prettier/eslint-config-prettier@v6.4.0...v6.5.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
# This is the commit message #35:

Bump eslint from 6.5.1 to 6.6.0

Bumps [eslint](https://github.com/eslint/eslint) from 6.5.1 to 6.6.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/master/CHANGELOG.md)
- [Commits](eslint/eslint@v6.5.1...v6.6.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
# This is the commit message #36:

[CHORE] refactor: Remove runloop usage in destroy module of integration/store… (emberjs#6646)

* refactor: Remove runloop usage in destroy module of integration/store-test

* fix linter errors

# This is the commit message #37:

Bump @types/ember__debug from 3.0.5 to 3.0.6 (emberjs#6647)

Bumps [@types/ember__debug](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/ember__debug) from 3.0.5 to 3.0.6.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/ember__debug)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
# This is the commit message #38:

Bump eslint-plugin-mocha from 6.2.0 to 6.2.1

Bumps [eslint-plugin-mocha](https://github.com/lo1tuma/eslint-plugin-mocha) from 6.2.0 to 6.2.1.
- [Release notes](https://github.com/lo1tuma/eslint-plugin-mocha/releases)
- [Changelog](https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/CHANGELOG.md)
- [Commits](lo1tuma/eslint-plugin-mocha@6.2.0...6.2.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
# This is the commit message #39:

Bump qunit-dom from 0.9.0 to 0.9.1

Bumps [qunit-dom](https://github.com/simplabs/qunit-dom) from 0.9.0 to 0.9.1.
- [Release notes](https://github.com/simplabs/qunit-dom/releases)
- [Changelog](https://github.com/simplabs/qunit-dom/blob/master/CHANGELOG.md)
- [Commits](mainmatter/qunit-dom@v0.9.0...v0.9.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
# This is the commit message #40:

Bump @typescript-eslint/parser from 2.5.0 to 2.6.0

Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 2.5.0 to 2.6.0.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/parser/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v2.6.0/packages/parser)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
# This is the commit message #41:

Bump @typescript-eslint/eslint-plugin from 2.5.0 to 2.6.0

Bumps [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) from 2.5.0 to 2.6.0.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v2.6.0/packages/eslint-plugin)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
# This is the commit message #42:

fix tracerbench command for renamed test app folder

# This is the commit message #43:

Setup har-remix

# This is the commit message #44:

replace server-replay with har-remix

# This is the commit message #45:

Use concurrently from node_modules instead of global installation

# This is the commit message #46:

wip

# This is the commit message #47:

Update bash script to use ember-data workspace for experiment

# This is the commit message #48:

relationship performance bash script updates

# This is the commit message #49:

removes line breaks

# This is the commit message #50:

removes .travis.yml from test app

# This is the commit message #51:

cleanup linting

# This is the commit message #52:

change eslint config

# This is the commit message #53:

cleanup

# This is the commit message #54:

remove comments

# This is the commit message #55:

updates azure-pipelines.yml

# This is the commit message #56:

adds tracerbench to github action workflow

# This is the commit message #57:

Update CI to install PM2 globally

# This is the commit message #58:

[CHORE] allow asserting all tests for deprecations (emberjs#6627)

* [CHORE] configure the ability to filter deprecations from assertNoDeprecations

* turn off helpers until tests are fixed

# This is the commit message #59:

[DOC] Close code block in the description
# This is the commit message #60:

Bump ember-qunit from 4.5.1 to 4.6.0

Bumps [ember-qunit](https://github.com/emberjs/ember-qunit) from 4.5.1 to 4.6.0.
- [Release notes](https://github.com/emberjs/ember-qunit/releases)
- [Changelog](https://github.com/emberjs/ember-qunit/blob/master/CHANGELOG.md)
- [Commits](emberjs/ember-qunit@v4.5.1...v4.6.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
# This is the commit message #61:

Bump ember-fetch from 6.7.1 to 6.7.2

Bumps [ember-fetch](https://github.com/ember-cli/ember-fetch) from 6.7.1 to 6.7.2.
- [Release notes](https://github.com/ember-cli/ember-fetch/releases)
- [Changelog](https://github.com/ember-cli/ember-fetch/blob/v6.7.2/CHANGELOG.md)
- [Commits](ember-cli/ember-fetch@v6.7.1...v6.7.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
# This is the commit message #62:

Bump ember-load-initializers from 2.1.0 to 2.1.1

Bumps [ember-load-initializers](https://github.com/ember-cli/ember-load-initializers) from 2.1.0 to 2.1.1.
- [Release notes](https://github.com/ember-cli/ember-load-initializers/releases)
- [Changelog](https://github.com/ember-cli/ember-load-initializers/blob/master/CHANGELOG.md)
- [Commits](ember-cli/ember-load-initializers@v2.1.0...v2.1.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
# This is the commit message #63:

Bump ember-source from 3.13.3 to 3.14.1

Bumps [ember-source](https://github.com/emberjs/ember.js) from 3.13.3 to 3.14.1.
- [Release notes](https://github.com/emberjs/ember.js/releases)
- [Changelog](https://github.com/emberjs/ember.js/blob/master/CHANGELOG.md)
- [Commits](emberjs/ember.js@v3.13.3...v3.14.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
# This is the commit message #64:

Bump eslint-plugin-ember from 7.2.0 to 7.3.0

Bumps [eslint-plugin-ember](https://github.com/ember-cli/eslint-plugin-ember) from 7.2.0 to 7.3.0.
- [Release notes](https://github.com/ember-cli/eslint-plugin-ember/releases)
- [Changelog](https://github.com/ember-cli/eslint-plugin-ember/blob/master/CHANGELOG.md)
- [Commits](ember-cli/eslint-plugin-ember@v7.2.0...v7.3.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
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

2 participants