Giter VIP home page Giter VIP logo

Comments (19)

t-richter avatar t-richter commented on May 30, 2024

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.

jmdobry avatar jmdobry commented on May 30, 2024

The computed property issue would be unrelated to the multiple belongsTo.

from js-data.

rigobcastro avatar rigobcastro commented on May 30, 2024

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.

jmdobry avatar jmdobry commented on May 30, 2024

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.

rigobcastro avatar rigobcastro commented on May 30, 2024

@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.

t-richter avatar t-richter commented on May 30, 2024

Very cool, indeed!
Does the 'ready' tag mean, you've already done this? Can we check this out already?
thx!

from js-data.

jmdobry avatar jmdobry commented on May 30, 2024

No, it means it's ready to be worked on.

from js-data.

pdorgambide avatar pdorgambide commented on May 30, 2024

+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.

jmdobry avatar jmdobry commented on May 30, 2024

I think inheritance among resource definitions is a separate issue from a single resource belonging to multiple parent resources.

from js-data.

pdorgambide avatar pdorgambide commented on May 30, 2024

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.

WillsB3 avatar WillsB3 commented on May 30, 2024

👍 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.

jmdobry avatar jmdobry commented on May 30, 2024

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.

WillsB3 avatar WillsB3 commented on May 30, 2024

@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.

jmdobry avatar jmdobry commented on May 30, 2024

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.

jmdobry avatar jmdobry commented on May 30, 2024

I'm going to release 2.0, then find a backwards compatible way to make this work.

from js-data.

WillsB3 avatar WillsB3 commented on May 30, 2024

👍

from js-data.

tfoxy avatar tfoxy commented on May 30, 2024

I'm willing to make a PR for this. Have you made any progress?

from js-data.

jmdobry avatar jmdobry commented on May 30, 2024

nope, nor do I have any ideas on the best way to implement or handle this

from js-data.

tfoxy avatar tfoxy commented on May 30, 2024

OK. I will check the code and try to come up with a solution.

from js-data.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.