Comments (19)
Sorry for posting this 'error' it seems it was casted due to my fault, 'EntityType' was not injected to the DS beforehand. I changed the resource definition from .factory to .run as described here:
http://www.js-data.io/v1.3.0/docs/js-data-angular
I still have a problem when trying to refer to a related item in a 'computed' property.
name: 'Entity',
endpoint: 'entities.json',
relations:
{
belongsTo:
{
Entity:
{
localField: 'parent',
localKey: 'parentId',
parent: false
}
,
EntityType:
{
localField: 'type',
localKey: 'typeId',
parent: false
}
}
,
hasMany:
{
Entity:
{
localField: 'children',
foreignKey: 'parentId'
}
}
},
computed: {
'label': ['name',
function (name) {
return name;
}
]
,
'icon': ['type',
function (type) {
logger.info("has type: " + type);
return (type && type.iconref ? type.iconref : 'fa fa-file');
}
]
}
the icon property will never resolve to anything else but "fa fa-file".
I'm not sure, if it's connected with the multiple belongsTo? Or a completely different issue?
Many thx anyway.
from js-data.
The computed property issue would be unrelated to the multiple belongsTo.
from js-data.
Hi, What is the solution for multiple belongsTo with parent? I need the nested url for many models., e.g:
groups/{id}/permissions
users/{id}/permissions
Any idea for this? Thanks.
from js-data.
I haven't solved it yet. js-data still assumes a resource can only have one parent. I'm thinking I might be able to add an option so you can specify which relation to use as the parent when you're doing find, update, destroy, etc.
from js-data.
@jmdobry Nice! I think this can optional via config, with this feature, the polymorphism would be posible http://en.wikipedia.org/wiki/Polymorphism_(computer_science) in js-data.
from js-data.
Very cool, indeed!
Does the 'ready' tag mean, you've already done this? Can we check this out already?
thx!
from js-data.
No, it means it's ready to be worked on.
from js-data.
+1 to allow inheritance on resource definition. One alternative could be something like:
var User = store.defineResource({
name: 'user',
relations: {
hasMany: {
comment: {
localField: 'comments',
foreignKey: 'userId'
}
},
belongsTo: {
organization: {
localKey: 'organizationId',
localField: 'organization',
// if you add this to a belongsTo relation
// then js-data will attempt to use
// a nested url structure, e.g. /organization/15/user/4
parent: true
}
}
}
});
var SecuredUser = store.defineResource({
name: 'secureduser',
hasOne: {
role: {
localField: 'role',
foreignKey: 'userId'
}
},
},User)
If inject an instace of secured
var userJson = {
id: 10,
name: 'John Anderson',
profile: {
email: 'John Anderson',
id: 18,
userId: 10
}
};
SecuredUser.inject(userJson);
User.get(10) // find on all child resource instances
//Parent relations from child instance.
SecuredUser.find(10).then(function(user){
SecuredUser.loadRelations(user, ['comment'])
});
from js-data.
I think inheritance among resource definitions is a separate issue from a single resource belonging to multiple parent resources.
from js-data.
Yes, you are right, the comment about polymorphism made me confuse. If it is not implemented I may open a new issue.
Thx a lot.
from js-data.
👍 I'm working on a large project where we are just trying to switch over to to js-data (and js-data-angular). We also have the need for resources to be able to specify multiple belongsTo relations.
from js-data.
You can already have multiple belongsTo relationships. This issue is here because right now you can only have one belongsTo relationship that is also set to parent: true
from js-data.
@jmdobry Right. Unfortunately our project has many models where the endpoint relies on many multiple parent models so we are hitting the same issue as the OP of this issue. We could take a look at implementing something with a view to opening a pull request if you can give us some guidance on the approach you would like to take?
from js-data.
I think the best way to address this might actually be with some architectural changes in 2.0. I'm wanting to make things a little more modular, with a more plugin-like architecture.
from js-data.
I'm going to release 2.0, then find a backwards compatible way to make this work.
from js-data.
👍
from js-data.
I'm willing to make a PR for this. Have you made any progress?
from js-data.
nope, nor do I have any ideas on the best way to implement or handle this
from js-data.
OK. I will check the code and try to come up with a solution.
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.