Comments (6)
Yes, say you load a bunch of users from the server, where each user has a bunch of posts, and each post has a bunch of comments, all in a single nested payload. If you've told JSData about the relations, than when that array of users is injected into the data store, the posts and comments will all be injected into their respective parts of the data store as well. In addition, by default JSData will try to link each injected item to its respective relations (in the example the hasMany links are already there from the JSON, payload, but the belongsTo links still need to be setup). So each comment will be given a reference to its user and its post, and each post will be given a reference to its user, etc. The linking can be done separate from the injection as well. If you never deal with nested payloads, or you don't care to have related items automatically linked to each other by the data store, than you probably don't need client-side relations.
Personally, I mostly use relations for the convenience of auto-injecting each part of nested payloads on GET requests. Otherwise I would need to make a separate request each for the users, posts, and comments (to continue the example).
Closing because Iām not sure this is an issue, if you are convinced that this is really a bug, please feel free to re-open the issue and add more information:
- good - Your versions of Angular, JSData, etc, relevant console logs/error, code examples that revealed the issue
- better - A plnkr, fiddle, or bin that demonstrates the issue
- best - A Pull Request that fixes the issue, including test coverage for the issue and the fix
Otherwise support is done via the mailing list.
from js-data.
Also, if someone were to contribute a PostgreSQL adapter for JSData (because JSData also runs on NodeJS), then you could use JSData on the frontend and on the backend, with a query syntax understand by both, plus isomorphic model definitions. Just sayin', that would be pretty cool. For some of my stuff I've got js-data + js-data-angular + js-data-schema(for client-side validations) on the frontend and js-data + js-data-rethinkdb(Database) + js-data-redis(Caching) + js-data-schema(Validations) on the backend. It's pretty slick.
With something as simple the following I get automatic caching with redis:
// simple example
var rethinkdbAdapter = new DSRethinkDBAdapter();
var redisAdapter = new DSRedisAdapter();
var store = new JSData.DS({
strategy: 'fallback',
fallbackAdapters: ['redis', 'rethinkdb']
});
store.registerAdapter('redis', redisAdapter);
store.registerAdapter('rethinkdb', rethinkdbAdapter, { default: true });
var User = store.defineResource('user');
app.get('/user/:id', function (req, res, next) {
// attempt to find the user with id "1" in redis (see "strategy" and "fallbackAdapters")
// if it's not in redis then look in rethinkdb
return User.find(1).then(function (user) {
// ensure the user is cached in redis
User.update(1, user, { adapter: 'redis' });
req.status(200).send(user).end();
}).catch(next);
});
from js-data.
This is a much better explanation that I could hope for. Thank you so much! I would love to use JS Data on the blackened with PostgreSQL as well. Maybe create a separate issue for PostreSQL adapter and assign label "help needed" or something. If there is a another DB adapter that could be used as a reference, would be helpful to include a link to it too. Maybe this will draw some PRs?
from js-data.
See #4
from js-data.
You are one step ahead :). I'll start digging into JS Data deep now and will help anywhere I can. Thank you very much for your continuous blazing support and awesome products.
from js-data.
š
from js-data.
Related Issues (20)
- 4.0.0 Release
- Record & Schema Classes
- Refactor code to use ecmascript Classes
- Publish all packages under @js-data team/scope
- Lerna mono repo? HOT 3
- Improve relations logic HOT 5
- jsdoc - api docs
- make orderBy work with locality by using Intl.collator
- Maximum call stack size exceeded when related models have different idAttribute
- datastore.get(mapper, '') returns a record (v3)
- Defining relations results to error when the Mapper recordClass is set to false (POJO) HOT 2
- Node6 incompatibilities with `querystrings` HOT 6
- hasOne relations aren't found in store for newly added records
- Hooks not working on mappers
- šØ Potential Improperly Controlled Modification of Object Prototype Attributes ('Prototype Pollution') (CWE-1321) HOT 3
- šØ Potential Improperly Controlled Modification of Object Prototype Attributes ('Prototype Pollution') (CWE-1321) HOT 7
- Trying to get in touch regarding a security issue
- SimpleStore doesn't support eager loading
- Getting 'DSUtils.deepMixIn' undefined when upgrading js-data package. HOT 1
- Lack of redirect from js-data.io to www.js-data.io HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ššš
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ā¤ļø Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from js-data.