-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Refreshing partially loaded records #51
Comments
Agree we need |
Why not have a separate model for your extended data/attributes (or a model to represent just the summary information)? |
The issue I find with creating a summary model is that in my situation the user has the ability to modify what I am summarizing so I end up right back at the same situation. The main model is modified, then I have to sync the summary, and now the adapter wants to commit my summary (which I could just ignore on the server), but seems like even more work arounds. |
@cloke yeah, similar situation here. |
I have updated the title to properly reflect the request. You could "sideload" the summary model in your adapter from any create or update request. It is now possible to load records into the store that are not dirty, so you can simply treat the "summary" model as read only and return an update to it from every request. |
I also really need a refresh method, but my use case is somewhat different, and the workaround @wycats suggested won't work for me. I'm writing a test-taking app - when the user decides to take a test, the Ember app creates a client-side test record and informs the server, which inserts it in the DB. The server starts up a background task to build the test (pick questions for it). I need my Ember app to keep reloading the test record every x seconds until it receives the full, built test. Does anyone have an idea for a simple workaround? |
@chanks this is probably not something that will go in the official package but this is my current take on the problem The main problem with reloading is to be able to "merge" underlying data. |
Thanks @tchak - I ran into one problem, where findQuery would try to call a nonexistent "call" function on the model I was refreshing (see here: tchak@130d308#L2R436). I defined an empty function for it to call, though, and things seem to be working alright now. |
sorry my bad, I fixed it in my local branch but have not pushed. Will push as soon as possible |
@chanks Hey, I juste updated my fork, it should be ok now and it is rebased on latest master. |
@tchak Great, thanks! |
I was running into a similar issue, wanting to load partial records up front and later load more detail based on what the user wants to see. The above referenced commits no longer exist so I came up with the following: App.Store = Ember.Store.extend
reload: (obj) ->
@adapter.find(this, obj.constructor, obj.get('id')) It seems to simple, can anyone see any problem with this approach? |
@abloom, i have extended your solution checking the record state. reload: function(record, rollback) {
if ( record.get('isDirty') ) {
if ( rollback === true ) {
// this will rollback the record to the last loaded values in the
// store
record.send('rollback');
} else {
// skip rollback values
var manager = record.get('stateManager'),
data = record.get('data');
record.withTransaction(function (t) {
var dirtyType = manager.getPath('currentState.dirtyType');
t.recordBecameClean(dirtyType, record);
});
data.adapterDidUpdate();
manager.goToState('loaded');
}
}
this.get('adapter').find(this, record.constructor, record.get('id') );
},
@wycats, @tchak, is it there any limitations to avoid reloading dirty records? I guess, i am hacking too much to get this functionality working. |
This issue doesn't seem to be progressing. At the moment we don't explicitly support partial loads. This is something we've considered and may add at some point in the future. |
I know this is a closed and old thread, but I'm curious if anyone has found a work around. I'm in a similar situation as @rvega. I can't load an the entire model in a list senario due to huge load times. I can shave off properties from the return w/ get parameters which makes the calls to the lists more performant. model.reload() helps because I can call model.reload() when I transition to a route which will display the full model. However if the list gets called again somewhere else in my app, the full model pops back to a partial model. Are there any ways around this? |
@brennanmceachran , I would suggest you to read this answer on SO. I think it's a good solution for this problem. |
@bobbus it's a potential way around a problem, but I don't think it's really a solution. You're modifying your backend/api because your frontend can't differentiate between fully and partially loaded models, and adding a second model on the frontend. Would that not mean all benefits of passing an object via {{#linkTo "singleroute"}} are gone? As you now have to load up your second model / you can't bank off of the data already loaded. I would have assumed that a call to a "full" model would just add the properties that were missing. :( |
You're right, I would not mean this will be the final solution, I just can't find a better workaround for now. I read partial objects loading is in the roadmap for ember-data but I guess it's not planned for now. |
I'd love to know if in the past 6 months, anyone's found a better solution. While @bobbus is right that there's a decent work around, it results in having to keep two separate models manually in sync (if you update/delete the full record, the teaser record doesn't know to be updated/deleted). |
We still haven't found one... but i think the jj-abrams branch is attempting to solve some of these issues... |
Any updates on this? I've been trying a few hacks, but haven't found a satisfactory solution :-/ |
Having the same issue. This seems like a really, really common use-case, no? Should definitely be something baked into the framework, IMO |
@chhopper @elsurudo I'm not sure, but I think the store support this feature at some point. I can see the push method taking a 'private' third optional argument which indicates the incoming data should be merge instead of replacing the current one. Perhaps even the update method is aimed to be public. You can use it, but the data you be normalized. @bradleypriest Do you know what's the status of this ? |
@bradleypriest thanks for the answer. So perhaps using the |
If someone gives me a use-case I'd be happy to work through it, all the examples are pre-jj-abrams ED so I don't know what people are struggling with |
@bradleypriest , a use case that is more complete but based on the one that started this thread is you have a blog with articles:
FWIW, a hacky way around this problem is to create a separate Model for the teaser (PostTeaser) versus the full (Post). Other than having to monkey with your backend to accommodate the api, the only problem I ran into is that this doesn't play nice with link_to ("link_to 'post' teaserobjectinstance" needs to point to the post route, not the teaser instance model route). I think if link_to would accept an id, instead of an object, this would work (i.e PostTeaser.id == Post.id, so if I could just pass the id to link_to, all might be well). |
@coladarci I was thinking about the same use case, it seems to be fair. In our app we have this kind of scenario. |
For the teasers and the full posts don't you already have two different endpoints then so they're two different models anyway? |
@bradleypriest , the way I set it up, no - I have different logic in my index api function versus my show api function. One asks for teasers and the other asks for the full. |
@sly7-7 - glad you linked to that - I gave up on this months ago before 1.0 was released. I'm thinking that was a later add. So I actually think between @bradleypriest point about having a different endpoint for teasers (which sounds reasonable) and the fact that link_to can take an ID, we are best off having two models and link_to with the id! For those who are confused about why this helps with the "refresh" issue - the moment we are switching models on the detail route, it'll be forced to pull a fresh model by id since there is nothing already loaded.. |
Yeah, I'm not even sure what the library would be able to provide here that would solve your problem in a simpler way. It doesn't seem like it's too much code on top of the basics whichever way you slice it |
@bradleypriest - I agreed completely - the link_to no longer working was a deal-breaker as I had to start manually forming complicated links with unbound variables and then those links' active states weren't working correctly as routes changed. The library would have to support a nondestructive load where existing models aren't wiped out if less data is provided from the server. That said, I can see why this would be problematic to say the least. |
@coladarci that support exists via the |
Interesting - it sounds like more work than to just maintain the teasers with a separate ObjectModel all together - is there an example of |
I had the same use case as many here. The way I solved it was to have a separate models (a long App.Payment and short App.PaymentSearchResult with some additional information about the search, e.g. distance to the search location). App.PaymentSearchResult stores the id of the corresponding App.Payment and I use linkto with the payment_id (note that just using payment via a DS.belongsTo will result in many unnecessary requests to your backend). Thanks to @sly7-7 for the hint! This is an ok solution for me, but since this is a very common use case it could make sense to have support for this baked in. For example, what if the backend passed a Also this approach required me to monkey-patch my backend (since requests now go to /payment_search_results). This isn't necessarily a problem but it would be nice to be able to specify a URL on a model-by-model basis (that way I could, for example route requests to /payments/search). This functionality used to exist in ED, but I believe it was removed. Does anyone have updates on this? |
There's now a Ember CLI addon to solve this at https://github.com/BookingSync/ember-data-partial-model |
Are there downsides to including that addon into ember-data core? |
@toobulkeh including properly this kind of functionality in core require to make all attributes accessors async (aka return a promise). This is something that is discussed but have a lot of implications. It could be not too much of a problem once async/await are more wildly used. |
# 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>
Here's the scenario:
You load a list of records with findQuery but the server only returns a few fields for each record. Afterwards, when the user navigates to a "detail" screen, you need to fetch the rest of the fields for the record from the server so you call App.store.find(type, id) and the store returns the already fetched record, there's no way to tell the store to fetch ask the adapter for the record again.
Also, any suggestions for a work around are appreciated.
The text was updated successfully, but these errors were encountered: